Claudio Silva
Claudio Silva

Reputation: 45

Android - Http Get Request

I'm trying to Get Request with code below but the stringbuilder is always null. The url is correct...

http://pastebin.com/mASvGmkq

EDIT

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;
}

Upvotes: 2

Views: 9605

Answers (1)

sschrass
sschrass

Reputation: 7166

I usually do it like this:

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

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

where output is a String-object.

Upvotes: 10

Related Questions