通过POST 提交数据
很多情况下,需要通过POST 将本地的数据发送给服务器,如下是一段实际的代码
public void MyFunction{
HttpClient httpclient = new DefaultHttpClient();
//你的URL
HttpPost httppost = new HttpPost("http://www.eoeandroid.com/post_datas.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
//Your DATA
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "eoeAndroid.com is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response;
response=httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
android http post请求
最新推荐文章于 2023-10-13 09:19:46 发布
1250

被折叠的 条评论
为什么被折叠?



