2013-02-22 68 views
-1

值我试图发送HTTP GET请求在URL中传递的网站通过HTTP GET在URL

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请求后,后端进程由服务器完成。

+0

什么问题,再一次? – SudoRahul 2013-02-22 04:01:04

+0

错误是什么? – Shoshi 2013-02-22 04:31:57

+0

发布您的整个logcat – Shoshi 2013-02-22 04:32:16

回答

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