本文整理匯總了Java中org.apache.http.client.methods.HttpEntityEnclosingRequestBase.setEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpEntityEnclosingRequestBase.setEntity方法的具體用法?Java HttpEntityEnclosingRequestBase.setEntity怎麽用?Java HttpEntityEnclosingRequestBase.setEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpEntityEnclosingRequestBase
的用法示例。
在下文中一共展示了HttpEntityEnclosingRequestBase.setEntity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: wrapEntity
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpRequestBase wrapEntity(SdkHttpFullRequest request,
HttpEntityEnclosingRequestBase entityEnclosingRequest) {
/*
* We should never reuse the entity of the previous request, since
* reading from the buffered entity will bypass reading from the
* original request content. And if the content contains InputStream
* wrappers that were added for validation-purpose (e.g.
* Md5DigestCalculationInputStream), these wrappers would never be
* read and updated again after AmazonHttpClient resets it in
* preparation for the retry. Eventually, these wrappers would
* return incorrect validation result.
*/
if (request.content().isPresent()) {
HttpEntity entity = new RepeatableInputStreamRequestEntity(request);
if (request.headers().get(HttpHeaders.CONTENT_LENGTH) == null) {
entity = ApacheUtils.newBufferedHttpEntity(entity);
}
entityEnclosingRequest.setEntity(entity);
}
return entityEnclosingRequest;
}
示例2: addPostParams
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private void addPostParams(HttpEntityEnclosingRequestBase request) throws UnsupportedEncodingException {
final MultipartEntityBuilder multipartBuilder = MultipartEntityBuilder.create();
List<NameValuePair> formParams = new ArrayList<>();
postVariables.forEach((name, values) -> values.forEach(value -> {
if (multipart) {
if (value.startsWith("@")) {
File f = new File(value.substring(1));
multipartBuilder.addBinaryBody(name, f, ContentType.DEFAULT_BINARY, f.getName());
} else {
multipartBuilder.addTextBody(name, value);
}
} else {
formParams.add(new BasicNameValuePair(name, value));
}
}));
if (multipart) {
request.setEntity(multipartBuilder.build());
} else {
request.setEntity(new UrlEncodedFormEntity(formParams));
}
}
示例3: post
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
public void post(Context context, String url, Header[] headers, RequestParams params, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = new HttpPost(url);
if (params != null) {
request.setEntity(paramsToEntity(params));
}
if (headers != null) {
request.setHeaders(headers);
}
sendRequest(this.httpClient, this.httpContext, request, contentType, responseHandler, context);
}
示例4: setEntityIfNonEmptyBody
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
Request<?> request) throws AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
HttpEntity entity = new ByteArrayEntity(body);
httpRequest.setEntity(entity);
}
}
示例5: setEntityIfNonEmptyBody
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest,
Request<?> request) throws AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
HttpEntity entity = new ByteArrayEntity(body);
httpRequest.setEntity(entity);
}
}
示例6: addEntityToRequestBase
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpEntityEnclosingRequestBase addEntityToRequestBase(HttpEntityEnclosingRequestBase
requestBase, HttpEntity
entity) {
if (entity != null) {
requestBase.setEntity(entity);
}
return requestBase;
}
示例7: addEntityToRequestBase
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
/**
* Applicable only to HttpRequest methods extending HttpEntityEnclosingRequestBase, which is for
* example not DELETE
*
* @param entity entity to be included within the request
* @param requestBase HttpRequest instance, must not be null
*/
private HttpEntityEnclosingRequestBase addEntityToRequestBase(HttpEntityEnclosingRequestBase requestBase, HttpEntity entity) {
if (entity != null) {
requestBase.setEntity(entity);
}
return requestBase;
}
示例8: setMethodAttributes
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
public static void setMethodAttributes(HttpEntityEnclosingRequestBase method, Request request) {
if(request.getBody() != null) {
method.setEntity(new ByteArrayEntity(request.getBody()));
}
if (request.getParts() != null) {
HttpEntity re = createMultipartEntities(request.getMultipartMode(), request.getParts());
method.setEntity(re);
}
setMethodAttributes((HttpRequestBase) method, request);
}
示例9: addParametersToPostRequest
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpEntityEnclosingRequestBase addParametersToPostRequest(HttpEntityEnclosingRequestBase postRequest, List<NameValuePair> params) throws UnsupportedEncodingException {
List<NameValuePair> nameValuePairs = params;
if(nameValuePairs!=null){
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePairs, "utf-8");
entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded"));
entity.setContentEncoding("utf-8");
postRequest.setEntity(entity);
}
return postRequest;
}
示例10: addEntityToRequestBase
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
/**
* Applicable only to HttpRequest methods extending
* HttpEntityEnclosingRequestBase, which is for example not DELETE
*
* @param entity entity to be included within the request
* @param requestBase HttpRequest instance, must not be null
*/
private HttpEntityEnclosingRequestBase addEntityToRequestBase(
HttpEntityEnclosingRequestBase requestBase, HttpEntity entity) {
if (entity != null) {
requestBase.setEntity(entity);
}
return requestBase;
}
示例11: 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 );
}
示例12: completeRequest
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
/** helper function to fill the request with header entries and posting body .
* */
private static HttpEntityEnclosingRequestBase completeRequest(HttpEntityEnclosingRequestBase request,
List<NameValuePair> headerEntries,
String postingBody) throws UnsupportedEncodingException{
if (null != completeRequest(request, headerEntries)){
// dump the post body UTF-8 will be used as the default encoding type.
if (null != postingBody && postingBody.length() > 0){
HttpEntity entity = new ByteArrayEntity(postingBody.getBytes("UTF-8"));
request.setHeader("Content-Length", Long.toString(entity.getContentLength()));
request.setEntity(entity);
}
}
return request;
}
示例13: setPayloadParams
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private void setPayloadParams(HttpEntityEnclosingRequestBase method) throws IOException
{
if (getBodyParams() != null)
{
StringEntity entity = new StringEntity(getBodyParams().asFormUrlEncodedString());
entity.setContentType("application/x-www-form-urlencoded");
method.setEntity(entity);
}
}
示例14: postSync
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
public String postSync(String url, Header[] headers, RequestParams params,
String contentType) {
HttpEntityEnclosingRequestBase request = new HttpPost(generateUrl(url));
if (params != null)
request.setEntity(invokeParamsToEntity(params, new DefaultHttpResponseHandler()));
if (headers != null)
request.setHeaders(headers);
return sendSyncRequest(getHttpClient(), getHttpContext(), request,
contentType);
}
示例15: addEntityToRequestBase
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //導入方法依賴的package包/類
private HttpEntityEnclosingRequestBase addEntityToRequestBase(HttpEntityEnclosingRequestBase requestBase, HttpEntity entity) {
if(entity != null){
requestBase.setEntity(entity);
}
return requestBase;
}