[英]http post connection in android
我正在用android开发应用程序,其中涉及将数据从应用程序发送到android中的url /服务器...有人可以告诉我如何进行此操作....在此先感谢Tushar
See this sample code. 请参阅此示例代码。 It will helps you.
它将为您提供帮助。
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);
}
You could use the code in this question. 您可以在此问题中使用代码。 I've explained how it works a bit as an answer to that question :)
我已经解释了它是如何工作的,作为对该问题的解答:)
Can anyone explain me this code? 谁能解释这个代码?
As an answer to your question: your URL goes in the httppost constructor: 回答您的问题:您的URL放在httppost构造函数中:
new HttpPost("http://www.yoursite.com/script.php");
You can read the rest of this topic for a quick howto: http://www.androidsnippets.org/snippets/36/ 您可以阅读本主题的其余部分,以获取快速的操作方法: http : //www.androidsnippets.org/snippets/36/
所有你需要做的是搜索,这个问题已经被问了很多次之前 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.