use of org.apache.hc.core5.http.Header in project retrofit by square.
the class RequestBuilderTest method contentTypeParameterHeaderOverrides.
@Test
public void contentTypeParameterHeaderOverrides() {
class Example {
//
@POST("/")
Call<ResponseBody> method(@Header("Content-Type") String contentType, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "Plain");
Request request = buildRequest(Example.class, "text/not-plain", body);
assertThat(request.body().contentType().toString()).isEqualTo("text/not-plain");
}
use of org.apache.hc.core5.http.Header in project retrofit by square.
the class RequestBuilderTest method headerParamArray.
@Test
public void headerParamArray() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Header("foo") String[] kit) {
return null;
}
}
Request request = buildRequest(Example.class, (Object) new String[] { "bar", null, "baz" });
assertThat(request.method()).isEqualTo("GET");
okhttp3.Headers headers = request.headers();
assertThat(headers.size()).isEqualTo(2);
assertThat(headers.values("foo")).containsExactly("bar", "baz");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of org.apache.hc.core5.http.Header in project retrofit by square.
the class RequestBuilderTest method headerParamList.
@Test
public void headerParamList() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Header("foo") List<String> kit) {
return null;
}
}
Request request = buildRequest(Example.class, Arrays.asList("bar", null, "baz"));
assertThat(request.method()).isEqualTo("GET");
okhttp3.Headers headers = request.headers();
assertThat(headers.size()).isEqualTo(2);
assertThat(headers.values("foo")).containsExactly("bar", "baz");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of org.apache.hc.core5.http.Header in project pact-jvm by DiUS.
the class PactProviderWithMultipleFragmentsTest method runTestWithPactVerificationsAndDefaultResponseValuesArePresent.
@Test
@PactVerifications({ @PactVerification(value = "test_provider2", fragment = "createFragment2") })
public void runTestWithPactVerificationsAndDefaultResponseValuesArePresent() throws IOException {
HttpResponse httpResponse = Request.get(mockTestProvider2.getUrl()).addHeader("testreqheader", "testreqheadervalue").execute().returnResponse();
assertThat(Arrays.stream(httpResponse.getHeaders("testresheader")).map(Header::getValue).collect(Collectors.toList()), is(equalTo(List.of("testresheadervalue"))));
}
use of org.apache.hc.core5.http.Header in project weicoder by wdcode.
the class HttpClient method post.
/**
* 模拟post提交
*
* @param url post提交地址
* @param data 提交参数
* @param header http头
* @param charset 编码
* @return 提交结果
*/
public static String post(String url, Map<String, String> data, Map<String, String> header, String charset) {
try {
// 获得HttpPost
HttpPost post = new HttpPost(url);
// 如果参数列表为空 data为空map
if (U.E.isNotEmpty(data)) {
// 声明参数列表
List<NameValuePair> list = Lists.newList(data.size());
// 设置参数
data.forEach((k, v) -> list.add(new BasicNameValuePair(k, W.C.toString(v))));
// 设置参数与 编码格式
post.setEntity(new UrlEncodedFormEntity(list));
}
// 添加http头
if (U.E.isNotEmpty(header))
header.forEach((k, v) -> post.addHeader(k, v));
LOG.debug("HttpClient post url={} data={} header={} charset={}", url, data, header, charset);
// 返回结果
return IOUtil.readString(CLIENT.execute(post).getEntity().getContent());
} catch (Exception e) {
LOG.error(e);
}
return StringConstants.EMPTY;
}
Aggregations