本文整理匯總了Java中org.apache.http.client.methods.HttpEntityEnclosingRequestBase.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpEntityEnclosingRequestBase.addHeader方法的具體用法?Java HttpEntityEnclosingRequestBase.addHeader怎麽用?Java HttpEntityEnclosingRequestBase.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpEntityEnclosingRequestBase
的用法示例。
在下文中一共展示了HttpEntityEnclosingRequestBase.addHeader方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeCallback
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private void executeCallback(HttpEntityEnclosingRequestBase request, String json, FutureCallback<HttpResponse> httpCallback) {
if (json != null && json.length() > 0) {
request.addHeader("Content-Type", "application/json");
if (!this.httpCompress) {
request.setEntity(generateStringEntity(json));
} else {
request.addHeader("Accept-Encoding", "gzip, deflate");
request.setEntity(generateGZIPCompressEntity(json));
}
}
FutureCallback<HttpResponse> responseCallback = null;
if (httpCallback != null) {
unCompletedTaskNum.incrementAndGet();
responseCallback = this.httpResponseCallbackFactory.wrapUpBaseHttpFutureCallback(httpCallback);
}
httpclient.execute(request,responseCallback);
}
示例2: executePostJsonStreamingResponse
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpStreamResponse executePostJsonStreamingResponse(HttpEntityEnclosingRequestBase requestBase,
String jsonBody,
Map<String, String> headers) throws HttpClientException {
try {
setRequestHeaders(headers, requestBase);
requestBase.setEntity(new StringEntity(jsonBody, ContentType.APPLICATION_JSON));
requestBase.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
return executeStream(requestBase);
} catch (IOException | UnsupportedCharsetException | OAuthCommunicationException | OAuthExpectationFailedException |
OAuthMessageSignerException e) {
String trimmedMethodBody = (jsonBody.length() > JSON_POST_LOG_LENGTH_LIMIT)
? jsonBody.substring(0, JSON_POST_LOG_LENGTH_LIMIT) : jsonBody;
throw new HttpClientException("Error executing " + requestBase.getMethod() + " request " +
"to " + clientPathToString(requestBase.getURI().getPath()) + " body:" + trimmedMethodBody, e);
}
}
示例3: addEntity
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private void addEntity ( HttpEntityEnclosingRequestBase req, String contentType, byte[] o )
{
final ByteArrayEntity input = new ByteArrayEntity ( o );
input.setContentType ( contentType );
req.addHeader ( "Content-Type", contentType );
req.setEntity ( input );
}
示例4: sendRequest
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpExampleResponse sendRequest(HttpEntityEnclosingRequestBase request, String data) {
try {
request.setEntity(new StringEntity(data));
request.addHeader(Headers.CONTENT_TYPE, "application/json");
return sendRequest(request);
} catch (UnsupportedEncodingException e) {
logException(e);
throw new RuntimeException(e);
}
}
示例5: execute
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(getPayload());
//
HttpEntityEnclosingRequestBase req = createHttpRequest();
req.addHeader("consumer_key", consumerKey);
req.addHeader("consumer_token", consumerToken);
req.addHeader("Content-Type", "application/json");
req.addHeader("Accept", "application/json");
req.setEntity(new StringEntity(json));
//
CloseableHttpClient client = HttpClientBuilder.create().build();
CloseableHttpResponse resp = client.execute(req);
int statusCode = resp.getStatusLine().getStatusCode();
try(InputStream in = resp.getEntity().getContent()) {
Map<String, ?> sdkmanResp = (Map<String, ?>) mapper.readValue(in, Map.class);
for (Map.Entry<String, ?> prop : sdkmanResp.entrySet()) {
System.out.println(prop.getKey() + ":" + prop.getValue());
}
}
if (statusCode < 200 || statusCode >= 300) {
throw new Exception("Server returned error " + resp.getStatusLine());
}
} catch (Exception e) {
throw new MojoExecutionException("Release failed", e);
}
}
示例6: addBodyToRequest
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private void addBodyToRequest(HttpEntityEnclosingRequestBase request) {
if (this.mRequestBody.equals(""))
return;
try {
StringEntity se = new StringEntity(this.mRequestBody);
se.setContentType(this.mRequestContentType);
request.setEntity(se);
request.addHeader("Content-Type", this.mRequestContentType);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例7: request
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
public static <T> T request(String url, Header[] headers, Map<String, String> data, Function<CloseableHttpResponse, T> res)
throws Exception {
T rslt = null;
CloseableHttpResponse response = null;
CloseableHttpClient httpclient = null;
// 시작 쿠키관리
List<Cookie> cookies = cookieStore.getCookies();
LOGGER.debug("Get cookies... : " + cookies);
try {
HttpEntityEnclosingRequestBase http = new HttpPost(url);
LOGGER.debug(url);
if (headers != null) {
for (Header header : headers) {
if (header == null)
continue;
http.addHeader(header);
}
}
httpclient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
// httpclient = HttpClients.createDefault();
// 시작 서버로 보낼 데이터를 묶음.
List<NameValuePair> dataArr = new ArrayList<NameValuePair>();
if (ValueUtil.isNotEmpty(data)) {
Iterator<String> iterator = data.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
String value = data.get(key);
dataArr.add(new BasicNameValuePair(key, value));
}
}
UrlEncodedFormEntity sendEntityData = new UrlEncodedFormEntity(dataArr, "UTF-8");
http.setEntity(sendEntityData);
// 끝 서버로 보낼 데이터를 묶음.
/* 프록시 체크 */
// if (USE_PROXY) {
// HttpHost proxy = new HttpHost(PROXY_URL, PROXY_PORT, "http");
// response = httpclient.execute(proxy, http);
// }
// else {
response = httpclient.execute(http);
// }
rslt = res.apply(response);
} finally {
if (response != null)
EntityUtils.consume(response.getEntity());
if (httpclient != null) {
httpclient.close();
}
}
return rslt;
}
示例8: put
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
@Override
public URI put(final WebResource resource, final boolean asBinary) {
init.await();
HttpEntityEnclosingRequestBase request = null;
if (resource.uri() == null || !resource.uri().isAbsolute()) {
request = new HttpPost(containerId);
final String name = slugText(resource);
if (name != null) {
request.addHeader("Slug", name);
}
if (asBinary) {
request.addHeader("Content-Disposition",
String.format("attachment; filename=%s", name != null ? name : "file.bin"));
}
} else {
request = new HttpPut(resource.uri());
if (!asBinary) {
request.addHeader("Prefer", "handling=lenient; received=\"minimal\"");
}
}
if (resource.representation() != null) {
request.setEntity(new InputStreamEntity(resource.representation()));
}
request.setHeader(HttpHeaders.CONTENT_TYPE, resource.contentType());
try {
return client.execute(request, (response -> {
final int status = response.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_CREATED) {
return URI.create(response.getFirstHeader(HttpHeaders.LOCATION).getValue());
} else if (status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_OK) {
return resource.uri();
} else {
throw new RuntimeException(String.format("Resource creation failed: %s; %s",
response.getStatusLine().toString(),
EntityUtils.toString(response.getEntity())));
}
}));
} catch (final Exception e) {
throw new RuntimeException(String.format("Error executing %s request to %s", request.getClass()
.getSimpleName(), request.getURI().toString()), e);
}
}
示例9: addHeaders
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private static void addHeaders(HttpEntityEnclosingRequestBase request) {
request.addHeader("User-Agent", USER_AGENT);
request.addHeader("accept", "application/json");
}