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


Java EntityUtils類代碼示例

本文整理匯總了Java中org.apache.http.util.EntityUtils的典型用法代碼示例。如果您正苦於以下問題:Java EntityUtils類的具體用法?Java EntityUtils怎麽用?Java EntityUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: DatarouterHttpResponse

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public DatarouterHttpResponse(HttpResponse response, HttpClientContext context,
		Consumer<HttpEntity> httpEntityConsumer){
	this.response = response;
	this.cookies = context.getCookieStore().getCookies();
	if(response != null){
		this.statusCode = response.getStatusLine().getStatusCode();
		this.entity = "";

		HttpEntity httpEntity = response.getEntity();
		if(httpEntity == null){
			return;
		}
		if(httpEntityConsumer != null){
			httpEntityConsumer.accept(httpEntity);
			return;
		}
		try{
			this.entity = EntityUtils.toString(httpEntity);
		}catch(IOException e){
			logger.error("Exception occurred while reading HTTP response entity", e);
		}finally{
			EntityUtils.consumeQuietly(httpEntity);
		}
	}
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:26,代碼來源:DatarouterHttpResponse.java

示例2: register

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
private void register(RegisterModel model) throws Exception {
	String url = "http://" + properties.getScouter().getHost() + ":" + properties.getScouter().getPort() + "/register";
	
       String param = new Gson().toJson(model);

       HttpPost post = new HttpPost(url);
       post.addHeader("Content-Type","application/json");
       post.setEntity(new StringEntity(param));
     
       CloseableHttpClient client = HttpClientBuilder.create().build();
     
       // send the post request
       HttpResponse response = client.execute(post);
       
       if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK || response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
       		logger.info("Register message sent to [{}] for [{}].", url, model.getObject().getDisplay());
       } else {
        	logger.warn("Register message sent failed. Verify below information.");
        	logger.warn("[URL] : " + url);
        	logger.warn("[Message] : " + param);
        	logger.warn("[Reason] : " + EntityUtils.toString(response.getEntity(), "UTF-8"));
       }
}
 
開發者ID:nices96,項目名稱:scouter-pulse-aws-monitor,代碼行數:24,代碼來源:GetMonitoringInstances.java

示例3: execute0

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
private static String execute0(HttpUriRequest httpUriRequest) throws Exception {
    CloseableHttpResponse closeableHttpResponse = null;

    String var4;
    try {
        closeableHttpResponse = closeableHttpClient.execute(httpUriRequest);
        String response = EntityUtils.toString(closeableHttpResponse.getEntity(), CHARSET);
        var4 = response;
    } catch (Exception var7) {
        throw var7;
    } finally {
        CloseUtils.close(closeableHttpResponse);
    }

    return var4;
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:17,代碼來源:OpenClient.java

示例4: checkOrderInfo

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public static String checkOrderInfo(TrainQuery query) {
    CloseableHttpClient httpClient = buildHttpClient();
    HttpPost httpPost = new HttpPost(UrlConfig.checkOrderInfo);

    httpPost.addHeader(CookieManager.cookieHeader());

    httpPost.setEntity(new StringEntity(genCheckOrderInfoParam(query), ContentType.create("application/x-www-form-urlencoded", Consts.UTF_8)));

    String result = StringUtils.EMPTY;
    try(CloseableHttpResponse response = httpClient.execute(httpPost)) {
        CookieManager.touch(response);
        result = EntityUtils.toString(response.getEntity());
    } catch (IOException e) {
        logger.error("checkUser error", e);
    }

    return result;
}
 
開發者ID:justice-code,項目名稱:Thrush,代碼行數:19,代碼來源:HttpRequest.java

示例5: Response

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
/**
 * Constructor
 *
 * @param response the http response
 */
public Response( final HttpResponse response )
{
	this.status = response.getStatusLine( );
	this.headers = response.getAllHeaders( );

	try
	{
		this.entityContent = EntityUtils.toByteArray( response.getEntity( ) );
		// EntityUtils.consume( response.getEntity( ) );
	}
	catch ( IllegalArgumentException | IOException e )
	{
		// ok
	}
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:21,代碼來源:Response.java

示例6: PostParam

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
private synchronized void PostParam(String url, List<BasicNameValuePair> parameters) throws Exception {
    HttpPost post = new HttpPost(url);
    String result = "";
    try {
        post.setEntity(new UrlEncodedFormEntity(parameters, "utf-8"));
        HttpResponse response = client.execute(post);
        HttpEntity httpEntity = response.getEntity();
        result = EntityUtils.toString(httpEntity, "utf-8");
    } catch (java.io.IOException e) {
        e.printStackTrace();
    } finally {

        JSONObject jsonObject = new JSONObject(result);
        String status = jsonObject.getString("status");
        if (!status.equals("success")) {
            throw new Exception(jsonObject.getString("msg"));
        }
        System.out.println(status);
    }
}
 
開發者ID:zackszhu,項目名稱:hack_sjtu_2017,代碼行數:21,代碼來源:HttpHandler.java

示例7: bytes

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
private byte[] bytes(HttpEntity entity){
    try {
        return EntityUtils.toByteArray(entity);
    } catch (IOException e) {
        error(e);
    }
    return null;
}
 
開發者ID:fcibook,項目名稱:QuickHttp,代碼行數:9,代碼來源:HttpResponseBody.java

示例8: getPassengers

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public static String getPassengers() {
    CloseableHttpClient httpClient = buildHttpClient();
    HttpPost httpPost = new HttpPost(UrlConfig.passenger);

    httpPost.addHeader(CookieManager.cookieHeader());

    String result = StringUtils.EMPTY;
    try(CloseableHttpResponse response = httpClient.execute(httpPost)) {
        result = EntityUtils.toString(response.getEntity());
        List<Passenger> passengers = PassengerUtil.parsePassenger(result);
        ResultManager.touch(passengers, "passengers");
    } catch (IOException e) {
        logger.error("getPassengers error", e);
    }

    return result;
}
 
開發者ID:justice-code,項目名稱:Thrush,代碼行數:18,代碼來源:HttpRequest.java

示例9: checkUser

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public static String checkUser() {
    CloseableHttpClient httpClient = buildHttpClient();
    HttpPost httpPost = new HttpPost(UrlConfig.checkUser);

    httpPost.addHeader(CookieManager.cookieHeader());

    String result = StringUtils.EMPTY;
    try(CloseableHttpResponse response = httpClient.execute(httpPost)) {
        CookieManager.touch(response);
        result = EntityUtils.toString(response.getEntity());
    } catch (IOException e) {
        logger.error("checkUser error", e);
    }

    return result;
}
 
開發者ID:justice-code,項目名稱:Thrush,代碼行數:17,代碼來源:HttpRequest.java

示例10: get

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
/**
 * Retorna os dados cadastrais referentes à credencial informada para conta digital
 * @param credencial: Conjunto de credencial e chave para a conta que deseja consultar
 * @return Cliente: Dados cadastrais da credencial informada
 */
public Cliente get(Credencial credencial)
        throws IOException, PJBankException {
    PJBankClient client = new PJBankClient(this.endPoint.concat("/").concat(credencial.getCredencial()));
    HttpGet httpGet = client.getHttpGetClient();
    httpGet.addHeader("x-chave-conta", credencial.getChave());

    String response = EntityUtils.toString(client.doRequest(httpGet).getEntity());

    JSONObject responseObject = new JSONObject(response);

    Cliente cliente = new Cliente();
    cliente.setNome(responseObject.getString("nome_empresa"));
    cliente.setCpfCnpj(responseObject.getString("cnpj"));

    Endereco endereco = new Endereco();
    endereco.setLogradouro(responseObject.getString("endereco"));
    endereco.setNumero(responseObject.getInt("numero"));
    endereco.setComplemento(responseObject.getString("complemento"));
    endereco.setBairro(responseObject.getString("bairro"));
    endereco.setCidade(responseObject.getString("cidade"));
    endereco.setEstado(responseObject.getString("estado"));
    endereco.setCep(responseObject.getString("cep"));

    cliente.setEndereco(endereco);

    String telefone = responseObject.getString("telefone");
    cliente.setDdd(Integer.parseInt(telefone.substring(0, 2)));
    cliente.setTelefone(Long.parseLong(telefone.substring(2, telefone.length())));

    cliente.setEmail(responseObject.getString("email"));
    cliente.setStatus("ativa".equalsIgnoreCase(responseObject.getString("status")));

    return cliente;
}
 
開發者ID:pjbank,項目名稱:pjbank-java-sdk,代碼行數:40,代碼來源:Credenciamento.java

示例11: getFile

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
/**
 * 下載文件
 *
 * @param url URL
 * @return 文件的二進製流,客戶端使用outputStream輸出為文件
 */
public static byte[] getFile(String url) {
	try {
		Request request = Request.Get(url);
		HttpEntity resEntity = request.execute().returnResponse().getEntity();
		return EntityUtils.toByteArray(resEntity);
	} catch (Exception e) {
		logger.error("postFile請求異常," + e.getMessage() + "\n post url:" + url);
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:18,代碼來源:HttpUtils.java

示例12: lastEtherPrice

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
/**
 * Returns the latest Ether price in Wei
 * @return Latest Ether price in Wei
 */
public EtherPrice lastEtherPrice() {

	HttpGet get = new HttpGet(PUBLIC_URL + "?module=stats&action=ethprice&apikey=" + API_KEY);
	String response = null;

	try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
		HttpEntity httpEntity = httpResponse.getEntity();
		response = EntityUtils.toString(httpEntity);
		EntityUtils.consume(httpEntity);
	} catch (IOException e) {
		e.printStackTrace();
	}

	@SuppressWarnings("rawtypes")
	ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);

	EtherPrice current = new EtherPrice();

	for(int j = 0; j < a.size(); j++)
		current.addData(a.get(j));

	return current;

}
 
開發者ID:Jaewan-Yun,項目名稱:Cryptocurrency-Java-Wrappers,代碼行數:29,代碼來源:Etherscan.java

示例13: main

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public static void main(String[] args) throws ParseException, IOException {
	HttpRequestUtil util = new HttpRequestUtil();
	CloseableHttpClient client = util.setDoubleInit();
	
	Map<String,String> map = new HashMap<>();
	CloseableHttpResponse httpPost = util.httpPost(client, "https://127.0.0.1:8443/pwp-web/login.do", map);
	
	HttpEntity entity = httpPost.getEntity();
	String string = EntityUtils.toString(entity, Charset.defaultCharset());
	
	System.out.println(string);
}
 
開發者ID:strictnerd,項目名稱:LearningSummary,代碼行數:13,代碼來源:HttpRequestUtil.java

示例14: ResponseWrap

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
public ResponseWrap(CloseableHttpClient httpClient, HttpRequestBase request, CloseableHttpResponse response, HttpClientContext context,
		ObjectMapper _mapper) {
	this.response = response;
	this.httpClient = httpClient;
	this.request = request;
	this.context = context;
	mapper = _mapper;

	try {
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			this.entity = new BufferedHttpEntity(entity);
		} else {
			this.entity = new BasicHttpEntity();
		}

		EntityUtils.consumeQuietly(entity);
		this.response.close();
	} catch (IOException e) {
		logger.warn(e.getMessage());
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:23,代碼來源:ResponseWrap.java

示例15: copyStaging

import org.apache.http.util.EntityUtils; //導入依賴的package包/類
protected String[] copyStaging(ItemId itemId, String token) throws IOException
{
	HttpResponse stagingResponse = execute(
		new HttpPost(appendQueryString(context.getBaseUrl() + "api/item/copy",
			queryString("uuid", itemId.getUuid(), "version", Integer.toString(itemId.getVersion())))), true, token);
	try
	{
		assertResponse(stagingResponse, 201, "201 not returned from staging creation");
	}
	finally
	{
		EntityUtils.consume(stagingResponse.getEntity());
	}
	ObjectNode stagingJson = (ObjectNode) getEntity(stagingResponse.getLastHeader("Location").getValue(), token);
	String stagingUuid = stagingJson.get("uuid").asText();
	String stagingDirUrl = stagingJson.get("links").get("self").asText();
	return new String[]{stagingUuid, stagingDirUrl};
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:AbstractItemApiTest.java


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