本文整理汇总了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;
}