本文整理汇总了Java中org.asynchttpclient.BoundRequestBuilder.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java BoundRequestBuilder.addHeader方法的具体用法?Java BoundRequestBuilder.addHeader怎么用?Java BoundRequestBuilder.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.asynchttpclient.BoundRequestBuilder
的用法示例。
在下文中一共展示了BoundRequestBuilder.addHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUploadArticle
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
public ArticleAttachments createUploadArticle(long articleId, File file, boolean inline) throws IOException {
BoundRequestBuilder builder = client.preparePost(tmpl("/help_center/articles/{id}/attachments.json").set("id", articleId).toString());
if (realm != null) {
builder.setRealm(realm);
} else {
builder.addHeader("Authorization", "Bearer " + oauthToken);
}
builder.setHeader("Content-Type", "multipart/form-data");
if (inline)
builder.addBodyPart(new StringPart("inline", "true"));
builder.addBodyPart(
new FilePart("file", file, "application/octet-stream", Charset.forName("UTF-8"), file.getName()));
final Request req = builder.build();
return complete(submit(req, handle(ArticleAttachments.class, "article_attachment")));
}
示例2: performRequest
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
private JsonObject performRequest(BoundRequestBuilder requestBuilder,
JsonObject body,
int expectedStatusCode,
String errorMessage)
throws StashClientException {
if (body != null) {
requestBuilder.setBody(body.toJson());
}
addAuth(requestBuilder);
requestBuilder.setFollowRedirect(true);
requestBuilder.addHeader("Content-Type", JSON.toString());
requestBuilder.addHeader("Accept", JSON.toString());
Request request = requestBuilder.build();
MDC.put(MDC_URL_KEY, request.getUrl());
MDC.put(MDC_METHOD_KEY, request.getMethod());
try {
Response response = httpClient.executeRequest(request).get(stashTimeout, TimeUnit.MILLISECONDS);
validateResponse(response, expectedStatusCode, errorMessage);
return extractResponse(response);
} catch (ExecutionException | TimeoutException | InterruptedException e) {
throw new StashClientException(e);
} finally {
MDC.remove(MDC_URL_KEY);
MDC.remove(MDC_METHOD_KEY);
}
}