当前位置: 首页>>代码示例>>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;未经允许,请勿转载。