当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponse.getEntity方法代码示例

本文整理汇总了Java中org.apache.http.HttpResponse.getEntity方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getEntity方法的具体用法?Java HttpResponse.getEntity怎么用?Java HttpResponse.getEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.getEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DatarouterHttpResponse

import org.apache.http.HttpResponse; //导入方法依赖的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: main

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.NTLM);
    httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
    NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", "");
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    HttpHost target = new HttpHost("apps.prorigo.com", 80, "http");

    // Make sure the same context is used to execute logically related requests
    HttpContext localContext = new BasicHttpContext();
    // Execute a cheap method first. This will trigger NTLM authentication
    HttpGet httpget = new HttpGet("/conference/Booking");
    HttpResponse response = httpclient.execute(target, httpget, localContext);
    HttpEntity entity = response.getEntity();
    System.out.println(EntityUtils.toString(entity));
}
 
开发者ID:Vedang18,项目名称:ProBOT,代码行数:18,代码来源:ClientAuthentication.java

示例3: getRouterMap

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, RouteConfig> getRouterMap() {
	RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Constants.DEFAULT_TIMEOUT)
			.setConnectionRequestTimeout(Constants.DEFAULT_TIMEOUT).setSocketTimeout(Constants.DEFAULT_TIMEOUT)
			.build();
	HttpClient httpClient = this.httpPool.getResource();
	try {
		StringBuilder sb = new StringBuilder(50);
		sb.append(this.getServerDesc().getRegistry())
				.append(this.getServerDesc().getRegistry().endsWith("/") ? "" : "/")
				.append(this.getServerDesc().getServerApp()).append("/routers");
		HttpGet get = new HttpGet(sb.toString());
		get.setConfig(requestConfig);
		// 创建参数队列
		HttpResponse response = httpClient.execute(get);
		HttpEntity entity = response.getEntity();
		String body = EntityUtils.toString(entity, "UTF-8");
		ObjectMapper mapper = JsonMapperUtil.getJsonMapper();
		return mapper.readValue(body, Map.class);
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		throw new RuntimeException(e);
	} finally {
		this.httpPool.release(httpClient);
	}
}
 
开发者ID:sylinklee,项目名称:netto_rpc,代码行数:27,代码来源:NginxServiceProvider.java

示例4: execute

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public void execute(ShardingContext context) {
    String host = "http://ddns.oray.com";
    String path = "/ph/update";
    String method = "GET";
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Authorization", "Basic " + Base64Utils.String2Base(OrayUser + ":" + OrayPwd));
    headers.put("User-Agent", "Oray");
    Map<String, String> querys = new HashMap<String, String>();

    try {
        HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            log.info(EntityUtils.toString(entity));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JiaXiaohei,项目名称:elasticjob-oray-client,代码行数:22,代码来源:DdnsClientJob.java

示例5: postHttp

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public String postHttp(String url, List<NameValuePair> params, List<NameValuePair> headers) throws IOException
{
    HttpPost post = new HttpPost(url);
    post.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
    post.getEntity().toString();

    if (headers != null)
    {
        for (NameValuePair header : headers)
        {
            post.addHeader(header.getName(), header.getValue());
        }
    }

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpResponse response = httpClient.execute(post);

    HttpEntity entity = response.getEntity();
    if (entity != null)
    {
        return EntityUtils.toString(entity);

    }
    return null;
}
 
开发者ID:TheCookieLab,项目名称:poloniex-api-java,代码行数:26,代码来源:HTTPClient.java

示例6: doGetJson

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public static JSONObject doGetJson(String url) {
    JSONObject jsonObject = null;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    HttpGet httpGet= new HttpGet(url);
    try {
        HttpResponse response=httpClient.execute(httpGet);
        HttpEntity enyity=response.getEntity();
        if (enyity != null) {
            String result=EntityUtils.toString(enyity,"UTF-8");
            logger.info("JSONObject: {}",result);
            jsonObject=JSONObject.fromObject(result);
        }
        httpGet.releaseConnection();
    } catch (IOException e) {
        logger.error("方法doGetJson失败:{}", e.getMessage());
    }

    return jsonObject;
}
 
开发者ID:SnackMen,项目名称:DanmuChat,代码行数:20,代码来源:JsonObject.java

示例7: sendMessage

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Sends MAVLink packet to RockBLOCK.
 * 
 * @param packet MAVLink packet to send.
 */
public void sendMessage(MAVLinkPacket packet) throws ClientProtocolException, IOException {
    if (packet == null)
        return;

    HttpPost httppost = new HttpPost(serviceURL);

    String data = Hex.encodeHexString(packet.encodePacket());

    // Request parameters and other properties.
    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair(PARAM_IMEI, imei));
    params.add(new BasicNameValuePair(PARAM_USERNAME, username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, password));
    params.add(new BasicNameValuePair(PARAM_DATA, data));
    httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

    HttpResponse response = httpclient.execute(httppost);

    HttpEntity entity = response.getEntity();

    String responseString = null;

    if (entity != null) {
        InputStream responseStream = entity.getContent();
        try {
            responseString = IOUtils.toString(responseStream);
        } finally {
            responseStream.close();
        }
    }

    if (responseString == null || responseString.startsWith("FAILED")) {
        throw new IOException(String.format("Failed to post message to RockBLOCK API. %s", responseString));
    }

    MAVLinkLogger.log(Level.INFO, "MT", packet);
}
 
开发者ID:envirover,项目名称:SPLGroundControl,代码行数:43,代码来源:RockBlockClient.java

示例8: getResponseEntity

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private String getResponseEntity(HttpResponse result) throws IOException {
    HttpEntity entity = result.getEntity();
    if (entity == null) {
        log.debug("Null response entity");
        return null;
    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        entity.writeTo(bos);
        byte[] bytes = bos.toByteArray();
        if (bytes == null) {
            bytes = "null".getBytes();
        }
        String response = new String(bytes);
        log.debug("Response with code " + result + ": " + response);
        return response;
    } finally {
        InputStream content = entity.getContent();
        if (content != null) {
            content.close();
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:25,代码来源:HttpUtils.java

示例9: sendPOSTUnchecked

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
protected HttpResponse sendPOSTUnchecked(UriTemplate schema, Map<String, String> params, List<NameValuePair> urlParams) {
    HttpResponse httpResponse;
    try {
        HttpPost req = new HttpPost(schema.buildUri(environment.baseURI, params));
        req.setEntity(new UrlEncodedFormEntity(urlParams));
        httpResponse = this.httpClient.execute(req);
        // Buffer the response entity in memory so we can release the connection safely
        HttpEntity old = httpResponse.getEntity();
        EntityUtils.updateEntity(httpResponse, new StringEntity(EntityUtils.toString(old)));
        req.releaseConnection();
    } catch (IOException e) {
        throw new WebmateApiClientException("Error sending POST to webmate API", e);
    }
    return httpResponse;
}
 
开发者ID:webmate-io,项目名称:webmate-sdk-java,代码行数:16,代码来源:WebmateApiClient.java

示例10: executePOST

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Execute the created HTTP Post Element and receive the respone
 *
 * @throws IOException
 *             General Error
 */
public void executePOST() throws IOException {
	try {
		HttpResponse response = httpclient.execute(httppost);
		httpEntity = response.getEntity();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:CCWI,项目名称:keywordEntityApiRankService,代码行数:15,代码来源:APIBasics.java

示例11: testbrokenLink

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Test
public void testbrokenLink() throws IOException, URISyntaxException {

    JSONObject object = new JSONObject();
    object.put("key", "sprSCKKWf8xUeXxEo6Bv0lE1sSjWRDkO");
    object.put("marketName", "eoemarket");
    object.put("count", 1);
    JSONArray data = new JSONArray();
    JSONObject o = new JSONObject();
    o.put("id", -1);
    o.put("link", "http://testsssssss");
    o.put("statusCode", 404);
    data.add(o);
    object.put("data", data);

    Reader input = new StringReader(object.toJSONString());
    byte[] binaryData = IOUtils.toByteArray(input, "UTF-8");
    String encodeBase64 = Base64.encodeBase64String(binaryData);

    String url = "http://localhost:8080/sjk-market/market/brokenLink.d";
    url = "http://app-t.sjk.ijinshan.com/market/brokenLink.d";
    URIBuilder builder = new URIBuilder(url);
    builder.setParameter("c", encodeBase64);
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(builder.build());
    HttpResponse response = httpclient.execute(httpPost);
    logger.debug("URI: {} , {}", url, response.getStatusLine());

    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    // be convinient to debug
    String rspJSON = IOUtils.toString(is, "UTF-8");
    System.out.println(rspJSON);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:35,代码来源:ControllerTest.java

示例12: getStreamFromNetwork

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
	HttpGet httpRequest = new HttpGet(imageUri);
	HttpResponse response = httpClient.execute(httpRequest);
	HttpEntity entity = response.getEntity();
	BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
	return bufHttpEntity.getContent();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:9,代码来源:HttpClientImageDownloader.java

示例13: doInBackground

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... params) {
    DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
    HttpPost httppost = new HttpPost("http://djtrinity.in/app/api/events.php");

    // Depends on your web service
    httppost.setHeader("Content-type", "application/json");

    InputStream inputStream = null;
    String result = null;
    try {
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();

        inputStream = entity.getContent();
        // json is UTF-8 by default
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        result = sb.toString();
    } catch (Exception e) {
        // Oops
    } finally {
        try {
            if (inputStream != null) inputStream.close();
        } catch (Exception squish) {
        }
    }
    return result;
}
 
开发者ID:Ronak-59,项目名称:Trinity-App,代码行数:35,代码来源:GetDataJSON.java

示例14: requestHttpGet

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public String requestHttpGet(String url_prex, String url, Map<String, String> paramMap, String authorization)
		throws HttpException, IOException {

	url = url_prex + url + "?" + StringUtil.createLinkString(paramMap);
	if (paramMap == null) {
		paramMap = new HashMap<>();
	}

	HttpRequestBase method = this.httpGetMethod(url, authorization);
	method.setConfig(requestConfig);
	long start = System.currentTimeMillis();
	HttpResponse response = client.execute(method);
	long end = System.currentTimeMillis();
	Logger.getGlobal().log(Level.INFO, String.valueOf(end - start));
	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,代码行数:31,代码来源:HttpUtilManager.java

示例15: deleteElementRangeIndexTemporalCollection

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public static void deleteElementRangeIndexTemporalCollection(String dbName, String collectionName) throws Exception
{
	DefaultHttpClient client = new DefaultHttpClient();
	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));

	HttpDelete del = new HttpDelete("http://"+host+":8002/manage/v2/databases/"+ dbName + "/temporal/collections?collection=" + collectionName + "&format=json");

	del.addHeader("Content-type", "application/json");
	del.addHeader("accept", "application/json");

	HttpResponse response = client.execute(del);
	HttpEntity respEntity = response.getEntity();
	if( response.getStatusLine().getStatusCode() == 400)
	{
		HttpEntity entity = response.getEntity();
		String responseString = EntityUtils.toString(entity, "UTF-8");
		System.out.println(responseString);
	}
	else if (respEntity != null) {
		// EntityUtils to get the response content
		String content =  EntityUtils.toString(respEntity);
		System.out.println(content);
	}
	else {
		System.out.println("Collection: " + collectionName + " deleted");
		System.out.println("==============================================================");
	}
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:31,代码来源:ConnectedRESTQA.java


注:本文中的org.apache.http.HttpResponse.getEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。