2013-02-22 77 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; 
     }