本文整理了Java中org.apache.http.client.fluent.Request.addHeader
方法的一些代码示例,展示了Request.addHeader
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.addHeader
方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:addHeader
暂无
代码示例来源:origin: jooby-project/jooby
public Request header(final String name, final Object value) {
req.addHeader(name, value.toString());
return this;
}
代码示例来源:origin: dreamhead/moco
private Request getRequest(final String url, final ImmutableMultimap<String, String> headers) {
Request request = Request.Get(url);
for (Map.Entry<String, String> entry : headers.entries()) {
request = request.addHeader(entry.getKey(), entry.getValue());
}
return request;
}
代码示例来源:origin: twosigma/beakerx
@Override
public String update(String name, String json) {
try {
String reply = Request.Post(LOCALHOST + this.context.getPort() + AUTOTRANSLTION)
.addHeader(AUTHORIZATION, auth())
.bodyString(createBody(name, json), ContentType.APPLICATION_JSON)
.execute().returnContent().asString();
if (!reply.equals("ok")) {
throw new RuntimeException(reply);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return json;
}
代码示例来源:origin: dreamhead/moco
public HttpResponse deleteForResponseWithHeaders(final String url, final ImmutableMultimap<String, String> headers)
throws IOException {
Request request = Request.Delete(url);
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.Get(remoteUrl("/proxy")).addHeader("foo", "foo");
String fooHeader = helper.execute(request).getFirstHeader("foo").getValue();
assertThat(fooHeader, is("foo_header"));
}
});
代码示例来源: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: twosigma/beakerx
@Override
public String get(String name) {
String valueString = "";
try {
valueString = Request
.Get(LOCALHOST + this.context.getPort() + AUTOTRANSLTION + this.context.getContextId() + "/" + name)
.addHeader(AUTHORIZATION, auth())
.execute()
.returnContent()
.asString();
} catch (IOException e) {
throw new RuntimeException(e);
}
return valueString;
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
Request request = Request.Get(root()).addHeader("Connection", "close");
HttpResponse response = helper.execute(request);
assertThat(response.getFirstHeader("Connection"), nullValue());
}
});
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
Request request = Request.Get(root()).version(HttpVersion.HTTP_1_0).addHeader("Connection", "keep-alive");
HttpResponse response = helper.execute(request);
String connection = response.getFirstHeader("Connection").getValue();
assertThat(connection, is("keep-alive"));
}
});
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
Request request = Request.Get(root()).version(HttpVersion.HTTP_1_1).addHeader("Connection", "keep-alive");
HttpResponse response = helper.execute(request);
assertThat(response.getFirstHeader("Connection"), nullValue());
}
});
代码示例来源: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_header_from_template() throws IOException {
runWithConfiguration("template.json");
Header header = helper.execute(Request.Get(remoteUrl("/header_template")).addHeader("foo", "bar"))
.getFirstHeader("foo");
assertThat(header.getValue(), is("bar"));
}
代码示例来源:origin: rancher/cattle
private static Request setHeaders(Request req, Region region) {
String publicKey = region.getPublicValue();
String secretKey = region.getSecretValue();
String encodedKeys = Base64.encodeBase64String(String.format("%s:%s", publicKey, secretKey).getBytes());
String auth = String.format("Basic %s", encodedKeys);
req.addHeader("Authorization", auth);
req.addHeader("X-ENFORCE-AUTHENTICATION", "true");
req.addHeader("Content-Type", "application/json");
req.addHeader("Accept", "application/json");
return req;
}
代码示例来源:origin: rancher/cattle
public HttpResponse getFromAzure(String azureAccessToken, String url) throws IOException {
logger.trace("URL for Azure API call: "+ url);
HttpResponse response = Request.Get(url).addHeader(AzureConstants.AUTHORIZATION, "Bearer " +
"" + azureAccessToken).addHeader(AzureConstants.ACCEPT, AzureConstants.APPLICATION_JSON).execute().returnResponse();
logger.debug("Response from Azure API: "+ response.getStatusLine());
logger.trace("Complete Response from Azure: "+ EntityUtils.toString(response.getEntity()));
return response;
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
private Request authenticatedDownloadRequest(URIBuilder uriBuilder, String blobId, String username) throws URISyntaxException {
AccessToken accessToken = userStepdefs.authenticate(username);
AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId);
if (attachmentAccessTokens.containsKey(key)) {
uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize());
}
Request request = Request.Get(uriBuilder.build());
if (accessToken != null) {
request.addHeader("Authorization", accessToken.serialize());
}
return request;
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
public void post(String requestBody) throws Exception {
response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/jmap").build())
.addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize())
.addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
.bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
.execute()
.returnResponse();
jsonPath = JsonPath.using(Configuration.defaultConfiguration()
.addOptions(Option.SUPPRESS_EXCEPTIONS))
.parse(response.getEntity().getContent());
}
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
private void trustForBlobId(String blobId, String username) throws Exception {
Response tokenGenerationResponse = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build())
.addHeader("Authorization", userStepdefs.authenticate(username).serialize())
.execute();
String serializedAttachmentAccessToken = tokenGenerationResponse.returnContent().asString();
attachmentAccessTokens.put(
new AttachmentAccessTokenKey(username, blobId),
AttachmentAccessToken.from(
serializedAttachmentAccessToken,
blobId));
}
代码示例来源: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();
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
@When("^\"([^\"]*)\" upload a too big content$")
public void userUploadTooBigContent(String username) throws Throwable {
AccessToken accessToken = userStepdefs.authenticate(username);
Request request = Request.Post(uploadUri)
.bodyStream(new BufferedInputStream(new ZeroedInputStream(_10M), _10M), org.apache.http.entity.ContentType.DEFAULT_BINARY);
if (accessToken != null) {
request.addHeader("Authorization", accessToken.serialize());
}
response = request.execute().returnResponse();
}
内容来源于网络,如有侵权,请联系作者删除!