开发者

Android 2.2 (level 8) httpclient.execute consistent timeout

I'm attempting to receive a response from a restful service, but receive a timeout. I am able to connect with the browser on my emulator, as I have configured an access point on the emulated device to pass through proxy (at work). Network seems to be fine. I've added:

<uses-permission android:name="android.permission.INTERNET" /> 

to the AndroidManifest.xml file.

The code is as follows:

public String getInputStreamFromUrl(String url) {
    String content = null;
    InputStream stream = null;
    try {
        HttpGe开发者_如何学编程t httpGet = new HttpGet(url);
        HttpClient httpclient = new DefaultHttpClient();
        // Execute HTTP Get Request
        HttpResponse response = httpclient.execute(httpGet);
        stream = response.getEntity().getContent();
        BufferedReader rd = new BufferedReader(new InputStreamReader(stream), 4096);
        String line;
        StringBuilder sb =  new StringBuilder();
        while ((line = rd.readLine()) != null) {
                sb.append(line);
        }
        rd.close();
        content = sb.toString();
            } catch (Exception e) {
        content = e.getMessage();
    }
    return content;

I know I should return a stream, but for the sake of just displaying some string values in a TextView widget, will suffice, so I'm just using the string to experiment. It consistently hangs on .execute, no matter what URL is passed. I've passed valid IP's as well, with nothin' doin'.

I appreciate your help in advance.


Try this. Put it at the top of the class.

System.setProperty("http.proxyHost", <your proxy host name>);
System.setProperty("http.proxyPort", <your proxy port>);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜