當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpPost.getEntity方法代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpPost.getEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpPost.getEntity方法的具體用法?Java HttpPost.getEntity怎麽用?Java HttpPost.getEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.methods.HttpPost的用法示例。


在下文中一共展示了HttpPost.getEntity方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cleanUpAfterExecute

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
/**
 * If passed httpMethod is of type HttpPost then obtain its entity. If the entity has an enclosing File then
 * delete it by invoking this method after the request has completed. The entity will have an enclosing File
 * only if it was too huge to fit into memory.
 *
 * @param httpMethod - the httpMethod to clean up.
 */
protected void cleanUpAfterExecute(final HttpRequestBase httpMethod) {
  if (httpMethod != null && httpMethod instanceof HttpPost) {
    HttpPost postMethod = (HttpPost) httpMethod;
    HttpEntity entity = postMethod.getEntity();
    if (entity != null && entity instanceof FileExposingFileEntity) {
      File tempRequestFile = ((FileExposingFileEntity) entity).getFile();
      try {
        boolean isDeleted = tempRequestFile.delete();
        if (!isDeleted) {
          handleFileNotDeletedError(tempRequestFile, null);
        }
      } catch (Exception ex) {
        handleFileNotDeletedError(tempRequestFile, ex);
      }
    }
  }
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:25,代碼來源:ApacheHttpClient4Dot3Engine.java

示例2: newDefaultRequest

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
@Test
public void query_parameters_moved_to_payload_for_post_request_with_no_payload
        () throws IOException, URISyntaxException {
    final Request<Object> request = newDefaultRequest(HttpMethodName.POST);
    request.withParameter("foo", "bar")
            .withParameter("alpha", "beta");
    HttpRequestBase requestBase = requestFactory.create(request, settings);
    Assert.assertThat(requestBase, Matchers.instanceOf(HttpPost
            .class));
    HttpPost post = (HttpPost) requestBase;
    HttpEntity entity = post.getEntity();
    byte[] actualContents = drainInputStream(entity.getContent());
    Assert.assertTrue(actualContents.length > 0);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:15,代碼來源:ApacheDefaultHttpRequestFactoryTest.java

示例3: requestHttpPost

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
public String requestHttpPost(String url_prex, String url, Map<String, String> params, String authorization)
		throws HttpException, IOException {

	url = url_prex + url;
	HttpPost method = this.httpPostMethod(url, authorization);
	String paramsstr = JSON.toJSONString(params);
	StringEntity sendEntity = new StringEntity(paramsstr);
	method.setEntity(sendEntity);
	method.setConfig(requestConfig);
	HttpEntity httpEntity = method.getEntity();
	for (int i = 0; i < method.getAllHeaders().length; i++) {
		Header header = method.getAllHeaders()[i];
	}

	HttpResponse response = client.execute(method);
	HttpEntity entity = response.getEntity();
	if (entity == null) {
		return "";
	}
	InputStream is = null;
	String responseData = "";
	try {
		is = entity.getContent();
		responseData = IOUtils.toString(is, "UTF-8");
	} finally {
		if (is != null) {
			is.close();
		}
	}
	return responseData;
}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:32,代碼來源:HttpUtilManager.java


注:本文中的org.apache.http.client.methods.HttpPost.getEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。