2

我正在尝试使用下面的代码获取请求,但字符串生成器始终为空。网址是正确的...

http://pastebin.com/mASvGmkq

编辑

public static StringBuilder sendHttpGet(String url) {

    HttpClient http = new DefaultHttpClient();
    StringBuilder buffer = null;

    try {
        HttpGet get = new HttpGet(url);
        HttpResponse resp = http.execute(get);
        buffer = inputStreamToString(resp.getEntity().getContent());
    }
    catch(Exception e) {
        debug("ERRO EM GET HTTP URL:\n" + url + "\n" + e);
        return null;
    }

    debug("GET HTTP URL OK:\n" + buffer);
    return buffer;
}
4

1 回答 1

10

我通常这样做:

try {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);

    HttpResponse httpResponse = httpClient.execute(httpGet);
    HttpEntity httpEntity = httpResponse.getEntity();
    output = EntityUtils.toString(httpEntity);
}

output字符串对象在哪里。

于 2013-01-18T17:52:08.853 回答