2011-01-25 65 views
0

我正在開發一個應用程序在android.Which涉及發送數據到android應用程序中的url/server ...可以有人告訴我如何追求與此....在此先感謝 Tushar在android中的http post連接

回答

0

您可以使用此問題中的代碼。我已經解釋它是如何工作有點爲這個問題的答案:)

Can anyone explain me this code?

作爲一個回答你的問題:你的網址雲在httppost構造:

new HttpPost("http://www.yoursite.com/script.php"); 

你可以請閱讀本主題的其餘部分以獲得快速的指導:http://www.androidsnippets.org/snippets/36/

+0

在那裏我要通過URL ....字符串或其他地方嗎?/ – User 2011-01-25 10:47:48

+0

我將其添加到答案,但快速谷歌會一直過於得到你的答案... – Nanne 2011-01-25 10:49:40

0

您只需要搜索,即可以多次詢問此問題before

+0

dave ,,,,好,,,,我知道了,,,,,你有沒有任何http連接的例子在Android現在 – User 2011-01-25 11:36:03

1

請參閱此示例代碼。它會幫助你。

HttpContext localContext = new BasicHttpContext(); 
     String ret = null; 
     HttpClient httpClient = new DefaultHttpClient(); 
     httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, 
       CookiePolicy.RFC_2109); 
     HttpPost httpPost = new HttpPost(url); 
     HttpResponse response = null; 
     StringEntity tmp = null; 
     httpPost.setHeader(
       "Accept", 
       "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); 
     httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); 
     try { 
      tmp = new StringEntity(data, "UTF-8"); 
     } catch (UnsupportedEncodingException e) { 
      Log.e("Your App Name Here", 
        "HttpUtils : UnsupportedEncodingException : " + e); 
     } 

     httpPost.setEntity(tmp); 
     try { 
      response = httpClient.execute(httpPost, localContext); 

      if (response != null) { 
       ret = EntityUtils.toString(response.getEntity()); 
       Log.i("result", ret); 
      } 
     } catch (Exception e) { 
      Log.e("Your App Name Here", "HttpUtils: " + e); 
     }