-1

我正在尝试使用在站点的 URL 中传递的值发送 HTTP GET 请求

http://somenthing.com/c/chk.php?val=somevalue

我使用了以下代码,但它似乎不起作用

HttpResponse response = null;
try {        
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
        request.setURI(new URI("http://somenthing.com/c/chk.php?val=somevalue"));
    response = client.execute(request);
    } 
    catch (URISyntaxException e) 
    {        
      e.printStackTrace();
    }
    catch (ClientProtocolException e) 
    {
      e.printStackTrace();
    }
    catch (IOException e) 
    {
      e.printStackTrace();
    }   
    return;

我没有收到任何错误,上面的代码在按下按钮时有效并且我已经使用了权限。

收到 HTTP GET 请求后,后端过程由服务器完成。

4

1 回答 1

0

我的解决方案是:

// ---Connects using HTTP GET---
        public static InputStream OpenHttpGETConnection(String url) {
            InputStream inputStream = null;
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
                inputStream = httpResponse.getEntity().getContent();
            } catch (Exception e) {
                Log.d("InputStream", e.getLocalizedMessage());
            }
            return inputStream;
        }
于 2013-02-22T04:06:21.433 回答