0

我正在尝试请求 HTTP,但它在我身上快死了

HttpResponse httpResponse = httpClient.execute(httpGet);

下面是我的代码...

public JSONObject getJSONFromUrl(String url) {
    // HTTP Request
    try {
        // defaultHttpClient
        System.out.println("CRAZY1");
        HttpClient httpClient = new DefaultHttpClient();
        System.out.println("CRAZY2");
        HttpGet httpGet = new HttpGet(url);
        System.out.println("CRAZY3");

        System.out.println("CRAZY4");
        HttpResponse httpResponse = httpClient.execute(httpGet);
        System.out.println("CRAZY5");
        HttpEntity httpEntity = httpResponse.getEntity();
        System.out.println("CRAZY6");
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

它告诉我线程正在以未捕获的异常退出。我确实在清单中启用了权限。可能是什么问题呢?

4

1 回答 1

0

确保您的 URL 包含 http://,否则 HttpGet 的构造函数将抛出 IllegalArgumentException。

于 2013-02-08T22:57:39.637 回答