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

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

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

Request.bodyByteArray介绍

暂无

代码示例

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

public String postBytes(final String url, final byte[] bytes, final Charset charset) throws IOException {
  return executeAsString(Request.Post(url)
      .bodyByteArray(bytes, ContentType.create("text/plain", charset)));
}

代码示例来源: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

public HttpResponse postForResponse(final String url, final String content, final String contentType)
    throws IOException {
  return execute(Request.Post(url)
      .addHeader(CONTENT_TYPE, contentType)
      .bodyByteArray(content.getBytes()));
}

代码示例来源: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: mgtechsoftware/smockin

void handleRequestData(final Request request, final Map<String, String> requestHeaders, final HttpClientCallDTO reqDto) {
  if (requestHeaders.containsValue(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
    final List<NameValuePair> postParameters = new ArrayList<>();
    if (reqDto.getBody() != null && reqDto.getBody().contains("&")) {
      final String[] formParameterPairsArray = reqDto.getBody().split("&");
      Stream.of(formParameterPairsArray).forEach(pa -> {
        if (pa.contains("=")) {
          final String[] pairArray = pa.split("=");
          if (pairArray.length == 2) {
            postParameters.add(new BasicNameValuePair(pairArray[0], pairArray[1]));
          }
        }
      });
    }
    request.bodyForm(postParameters);
    return;
  }
  request.bodyByteArray((reqDto.getBody() != null)?reqDto.getBody().getBytes():null);
}

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

static void handleRequestData(final Request request, final Map<String, String> requestHeaders, final HttpClientCallDTO reqDto) {
  if (requestHeaders.containsValue(MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
    final List<NameValuePair> postParameters = new ArrayList<>();
    if (reqDto.getBody() != null && reqDto.getBody().contains("&")) {
      final String[] formParameterPairsArray = reqDto.getBody().split("&");
      Stream.of(formParameterPairsArray).forEach(pa -> {
        if (pa.contains("=")) {
          final String[] pairArray = pa.split("=");
          if (pairArray.length == 2) {
            postParameters.add(new BasicNameValuePair(pairArray[0], pairArray[1]));
          }
        }
      });
    }
    request.bodyForm(postParameters);
    return;
  }
  request.bodyByteArray((reqDto.getBody() != null)?reqDto.getBody().getBytes():null);
}

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

public static HttpClientResponseDTO patch(final HttpClientCallDTO reqDto) throws IOException {
  final Request request = Request.Patch(reqDto.getUrl())
      .bodyByteArray((reqDto.getBody() != null)?reqDto.getBody().getBytes():null);
  return executeRequest(request, reqDto.getHeaders());
}

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

HttpClientResponseDTO patch(final HttpClientCallDTO reqDto) throws IOException {
  final Request request = Request.Patch(reqDto.getUrl())
      .bodyByteArray((reqDto.getBody() != null)?reqDto.getBody().getBytes():null);
  return executeRequest(request, reqDto.getHeaders());
}

代码示例来源:origin: ExpediaDotCom/adaptive-alerting

@Override
public AnomalyResult classify(MetricData metricData) {
  notNull(metricData, "metricData can't be null");
  
  AnomalyLevel level;
  try {
    final AquilaRequest aquilaRequest = toAquilaRequest(metricData);
    final byte[] aquilaRequestBytes = objectMapper.writeValueAsBytes(aquilaRequest);
    final Content content = Request.Post(uri)
        .addHeader("Content-Type", "application/json")
        .bodyByteArray(aquilaRequestBytes)
        .execute()
        .returnContent();
    final AquilaResponse aquilaResponse = objectMapper.readValue(content.asBytes(), AquilaResponse.class);
    level = AnomalyLevel.valueOf(aquilaResponse.getLevel());
  } catch (IOException e) {
    log.error("Classification failed: " + e.getMessage(), e);
    level = AnomalyLevel.UNKNOWN;
  }
  
  return new AnomalyResult(uuid, metricData, level);
}

代码示例来源:origin: de.matrixweb.smaller/client-common

/**
 * @param host
 * @param port
 * @param proxyhost
 * @param proxyport
 * @param bytes
 * @return the response as {@link InputStream}
 * @throws ExecutionException
 */
public byte[] send(final String host, final String port,
  final String proxyhost, final String proxyport, final byte[] bytes)
  throws ExecutionException {
 try {
  final Request request = Request.Post("http://" + host + ":" + port)
    .socketTimeout(0).connectTimeout(0);
  if (proxyhost != null && proxyport != null) {
   request.viaProxy(new HttpHost(proxyhost, Integer.valueOf(proxyport)));
  }
  final HttpResponse response = request
    .addHeader(Version.HEADER, Version.getCurrentVersion().toString())
    .bodyByteArray(bytes).execute().returnResponse();
  return handleResponse(response);
 } catch (final Exception e) {
  if (e instanceof SmallerException) {
   throw (SmallerException) e;
  }
  throw new ExecutionException("Failed to send zip file", e);
 }
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@When("^\"([^\"]*)\" upload a content without content type$")
public void userUploadContentWithoutContentType(String username) throws Throwable {
  AccessToken accessToken = userStepdefs.authenticate(username);
  Request request = Request.Post(uploadUri)
      .bodyByteArray("some text".getBytes(StandardCharsets.UTF_8));
  if (accessToken != null) {
    request.addHeader("Authorization", accessToken.serialize());
  }
  response = request.execute().returnResponse();
}

相关文章