org.apache.http.client.fluent.Request.Put()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中org.apache.http.client.fluent.Request.Put方法的一些代码示例,展示了Request.Put的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.Put方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:Put

Request.Put介绍

暂无

代码示例

代码示例来源:origin: jooby-project/jooby

public Request put(final String path) {
 this.req = new Request(this, executor(), org.apache.http.client.fluent.Request.Put(host
   + path));
 return req;
}

代码示例来源:origin: dreamhead/moco

public HttpResponse putForResponseWithHeaders(final String url, final String content,
                       final ImmutableMultimap<String, String> headers) throws IOException {
  Request request = Request.Put(url)
      .bodyByteArray(content.getBytes());
  for (Map.Entry<String, String> entry : headers.entries()) {
    request.addHeader(entry.getKey(), entry.getValue());
  }
  return execute(request);
}

代码示例来源:origin: dreamhead/moco

@Override
  public void run() throws IOException {
    Request request = Request.Put(remoteUrl("/foo"));
    assertThat(helper.executeAsString(request), is("bar"));
  }
});

代码示例来源:origin: dreamhead/moco

@Override
  public void run() throws IOException {
    Request request = Request.Put(root()).bodyByteArray("foo".getBytes());
    assertThat(helper.executeAsString(request), is("bar"));
  }
});

代码示例来源:origin: dreamhead/moco

public HttpResponse putForResponse(final String url, final String content) throws IOException {
  return execute(Request.Put(url)
      .addHeader(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString())
      .bodyByteArray(content.getBytes()));
}

代码示例来源:origin: dreamhead/moco

@Test
public void should_return_expected_response_based_on_specified_put_request() throws IOException {
  runWithConfiguration("put_method.json");
  Request request = Request.Put(remoteUrl("/put"));
  assertThat(helper.executeAsString(request), is("response_for_put_method"));
}

代码示例来源:origin: dreamhead/moco

@Override
  public void run() throws IOException {
    assertThat(helper.get(remoteUrl("/proxy")), is("get_proxy"));
    assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("post_proxy"));
    Request putRequest = Request.Put(remoteUrl("/proxy")).bodyString("proxy", ContentType.DEFAULT_TEXT);
    assertThat(helper.executeAsString(putRequest), is("put_proxy"));
    Request deleteRequest = Request.Delete(remoteUrl("/proxy"));
    assertThat(helper.executeAsString(deleteRequest), is("delete_proxy"));
    Request headRequest = Request.Head(remoteUrl("/proxy"));
    StatusLine headStatusLine = helper.execute(headRequest).getStatusLine();
    assertThat(headStatusLine.getStatusCode(), is(200));
    Request optionsRequest = Request.Options(remoteUrl("/proxy"));
    assertThat(helper.executeAsString(optionsRequest), is("options_proxy"));
    Request traceRequest = Request.Trace(remoteUrl("/proxy"));
    assertThat(helper.executeAsString(traceRequest), is("trace_proxy"));
  }
});

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@Override
public Request put(String partialUrl) {
  String url = baseUrl + partialUrl;
  return Request.Put(url);
}

代码示例来源:origin: com.adobe.acs/acs-aem-commons-bundle

@Override
public Request put(String partialUrl) {
  String url = baseUrl + partialUrl;
  return Request.Put(url);
}

代码示例来源:origin: com.github.rebue.wheel/wheel-core

/**
 * 发出PUT请求
 * 
 * @param url
 *            请求的地址
 * @return 响应的字符串
 */
public static String put(String url) throws IOException {
  _log.info("准备发出只有URL的PUT请求: {}", url);
  try {
    String result = Request.Put(url).execute().returnContent().asString();
    _log.info("接收到response的信息: {}", result);
    return result;
  } catch (IOException e) {
    _log.error("HTTP请求出现异常:" + e.getMessage(), e);
    throw e;
  }
}

代码示例来源:origin: mesosphere/dcos-commons

/**
 * Create a new secret.
 *
 * @param path   location to create the secret
 * @param secret a secret definition
 * @throws IOException if the create operation failed to complete
 */
public void create(String path, Payload secret) throws IOException {
 Request httpRequest = Request.Put(uriForPath(path))
   .bodyString(OBJECT_MAPPER.writeValueAsString(secret), ContentType.APPLICATION_JSON);
 query("create", path, httpRequest, HttpStatus.SC_CREATED);
}

代码示例来源:origin: com.github.rebue.wheel/wheel-core

/**
 * 发出PUT请求(参数为json形式的字符串)
 * 
 * @param url
 *            请求的地址
 * @param jsonParams
 *            请求的参数
 * @return 响应的字符串
 */
public static String putByJsonParams(String url, String jsonParams) throws IOException {
  _log.info("准备发出带json参数的PUT请求: {} {}", url, jsonParams);
  try {
    String result = Request.Put(url).bodyString(jsonParams, ContentType.APPLICATION_JSON).execute().returnContent().asString();
    _log.info("接收到response的信息: {}", result);
    return result;
  } catch (IOException e) {
    _log.error("HTTP请求出现异常:" + e.getMessage(), e);
    throw e;
  }
}

代码示例来源:origin: com.github.dcshock/consul-rest-client

/**
   * Issue a PUT to the given URL without a body.
   */
  public static HttpResp put(final String url) throws IOException {
    return Http.toHttpResp(executor.execute(Request.Put(url))
        .returnResponse()
    );
  }
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-tika

@Override
public Optional<InputStream> recursiveMetaDataAsJson(InputStream inputStream, String contentType) {
  try {
    return Optional.ofNullable(
        Request.Put(recursiveMetaData)
          .socketTimeout(tikaConfiguration.getTimeoutInMillis())
          .bodyStream(inputStream, ContentType.create(contentType))
          .execute()
          .returnContent()
          .asStream());
  } catch (IOException e) {
    LOGGER.warn("Failing to call Tika for content type {}", contentType, e);
    return Optional.empty();
  }
}

代码示例来源:origin: com.github.rebue.wheel/wheel-core

/**
 * 发出PUT请求(将Map对象转为请求的FORM参数)
 * 
 * @param url
 *            请求的地址
 * @param requestParams
 *            请求的参数
 * @return 响应的字符串
 */
public static String putByFormParams(String url, Map<String, Object> requestParams) throws IOException {
  _log.info("准备发出带FORM参数的PUT请求: {}", url);
  Form form = Form.form();
  for (Entry<String, Object> requestParam : requestParams.entrySet()) {
    form.add(requestParam.getKey(), requestParam.getValue().toString());
  }
  try {
    String result = Request.Put(url).bodyForm(form.build()).execute().returnContent().asString();
    _log.info("接收到response的信息: {}", result);
    return result;
  } catch (IOException e) {
    _log.error("HTTP请求出现异常:" + e.getMessage(), e);
    throw e;
  }
}

代码示例来源:origin: com.github.dcshock/consul-rest-client

/**
 * Issue a PUT to the given URL with a JSON body.
 */
public static HttpResp put(final String url, final String body) throws IOException {
  return Http.toHttpResp(executor.execute(Request.Put(url)
      .bodyString(body, ContentType.APPLICATION_JSON))
      .returnResponse()
  );
}

代码示例来源:origin: Talend/components

/**
 * Executes Http Put request
 * 
 * @param resource REST API resource. E. g. issue/{issueId}
 * @param body message body
 * @return response status code and body
 * @throws ClientProtocolException
 * @throws IOException
 */
public JiraResponse put(String resource, String body) throws IOException {
  Request put = Request.Put(hostPort + resource).bodyString(body, contentType);
  for (Header header : headers) {
    put.addHeader(header);
  }
  executor.clearCookies();
  Response response = executor.execute(put);
  HttpResponse httpResponse = response.returnResponse();
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();
  HttpEntity entity = httpResponse.getEntity();
  String entityBody = "";
  if (entity != null && statusCode != SC_UNAUTHORIZED) {
    entityBody = EntityUtils.toString(entity);
  }
  return new JiraResponse(statusCode, entityBody);
}

代码示例来源:origin: mgtechsoftware/smockin

public static HttpClientResponseDTO put(final HttpClientCallDTO reqDto) throws IOException {
  final Request request = Request.Put(reqDto.getUrl());
  handleRequestData(request, reqDto.getHeaders(), reqDto);
  return executeRequest(request, reqDto.getHeaders());
}

代码示例来源:origin: mgtechsoftware/smockin

HttpClientResponseDTO put(final HttpClientCallDTO reqDto) throws IOException {
  final Request request = Request.Put(reqDto.getUrl());
  handleRequestData(request, reqDto.getHeaders(), reqDto);
  return executeRequest(request, reqDto.getHeaders());
}

代码示例来源:origin: edu.jhuapl.dorset/dorset-core

private Response put(HttpRequest request) throws IOException {
  Request apacheRequest = Request.Put(request.getUrl());
  if (request.getBody() != null) {
    ContentType ct = ContentType.create(request.getContentType().getMimeType(),
            request.getContentType().getCharset());
    apacheRequest.bodyString(request.getBody(), ct);
  } else if (request.getBodyForm() != null) {
    apacheRequest.bodyForm(buildFormBody(request.getBodyForm()));
  }
  prepareRequest(apacheRequest);
  return apacheRequest.execute();
}

相关文章