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


Java HttpResponse.getEntity方法代码示例

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


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

示例1: get

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
public static Hostplace get(String ip) throws Exception {
    HttpGet httppost = new HttpGet(Geocode.url + "/" + ip);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        if (json.getString("status").equals("fail"))
            throw new Exception();

        Hostplace hostplace = Hostplace.getJson(json);
        return hostplace;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:22,代码来源:Geocode.java

示例2: getBlock

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
public static Block getBlock(String blockhash) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/block/" + blockhash);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        Block block = Block.getJson(json);
        return block;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例3: getBlockHash

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
public static String getBlockHash(String height) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/block-index/" + height);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        String hash = json.getString("blockHash");
        return hash;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例4: getTx

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
public static Tx getTx(String hash) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/tx/" + hash);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        Tx tx = Tx.getJson(json);
        return tx;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例5: getHttpDocument

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
/**
 * Returns the content of a http request as an XML Document.  This is to be
 * used only when we know the response to a request will be XML.  Otherwise,
 * this will probably throw an exception.
 *
 * @param httpclient an active HTTP session
 * @param httpreq    an HTTP request (GET or POST)
 * @return a Document containing the contents of the response
 */
private static Document getHttpDocument(@NonNull CloseableHttpClient httpclient,
                                        @NonNull HttpUriRequest httpreq) throws Exception {
    // Remember the last request. We might want to abort it later.
    mLastRequest = httpreq;

    HttpResponse response = httpclient.execute(httpreq);

    HttpEntity entity = response.getEntity();

    return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(entity.getContent());
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:21,代码来源:WikiUtils.java

示例6: deletePost

import cz.msebera.android.httpclient.HttpResponse; //导入方法依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
    String url = getUsingUrl(true) + "v1/posts/" + model.postNumber;
    HttpEntity entity = ExtendedMultipartBuilder.create().setDelegates(listener, task).addString("password", model.password).build();
    HttpUriRequest request = null;
    HttpResponse response = null;
    HttpEntity responseEntity = null;
    try {
        request = RequestBuilder.delete().setUri(url).setEntity(entity).build();
        response = httpClient.execute(request);
        StatusLine status = response.getStatusLine();
        switch (status.getStatusCode()) {
            case 200:
                return null;
            case 400:
                responseEntity = response.getEntity();
                InputStream stream = IOUtils.modifyInputStream(responseEntity.getContent(), null, task);
                JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new InputStreamReader(stream))));
                throw new Exception(json.getString("message"));
            default:
                throw new Exception(status.getStatusCode() + " - " + status.getReasonPhrase());
        }
    } finally {
        try { if (request != null) request.abort(); } catch (Exception e) {}
        EntityUtils.consumeQuietly(responseEntity);
        if (response != null && response instanceof Closeable) IOUtils.closeQuietly((Closeable) response);
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:29,代码来源:HorochanModule.java


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