本文整理汇总了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);
}
}
}
示例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"));
}
}
示例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;
}
示例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;
}
示例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
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
}
示例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};
}