如何添加Android的HTTP POST的参数? [英] how to add parameters in android http post?

查看:422
本文介绍了如何添加Android的HTTP POST的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我试图用下面的教程上传文件到PHP服务器 <一href="http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html">http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html

i am trying to upload file to php server using following tutorial http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html

我不知道如何添加像

用户id =12312;在它的SessionID =234

userid="12312";sessionid="234" in it.

任何一个指导我如何实现这一目标?

any one guide me how to achieve this?

任何帮助将是AP preciated。

any help would be appreciated.

推荐答案

在互联网上,你会发现有很多的例子

over the internet you will find a lot of examples

如何添加参数?你必须有这样的事情。

how to add parameters? you must have something like.

// Add your data  
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);  
nameValuePairs.add(new BasicNameValuePair("userid", "12312"));  
nameValuePairs.add(new BasicNameValuePair("sessionid", "234"));  
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  



public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/myexample.php");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("id", "12345"));
    nameValuePairs.add(new BasicNameValuePair("stringdata", "stackoverflow.com is Cool!"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}
}

这篇关于如何添加Android的HTTP POST的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆