public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
//you can add all the parameters your php needs in the BasicNameValuePair.
//The first parameter refers to the name in the php field for example
// $id=$_POST['id']; the second parameter is the value.
List nameValuePairs = new ArrayList(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev 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
}}
上面的代码将发送如下数组:
[id = 12345,stringdata = AndDev很酷!]
如果你想要一个bidimentional数组,你应该这样做
Bundle b= new Bundle();
b.putString("id", "12345");
b.putString("stringdata", "Android is Cool");
nameValuePairs.add(new BasicNameValuePair("info", b.toString()));
这将创建一个包含数组的数组:
[info=Bundle[{id=12345, stringdata=Android is Cool}]]
我希望这就是你想要的.