-1
我想在我的web和android之間進行通信,我有困難從我的android發送數據到php頁面,我正在使用JSON進行通信,我該如何做到這一點請幫助我........如何使用JSON發送數據到php頁面android
我想在我的web和android之間進行通信,我有困難從我的android發送數據到php頁面,我正在使用JSON進行通信,我該如何做到這一點請幫助我........如何使用JSON發送數據到php頁面android
爲什麼不實際做一個POST請求從您的設備到php頁面?畢竟PHP真的很擅長處理請求,所以它不應該是一個問題。嘗試了這一點:
Java:
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://yoursite.com");
try {
// Add your data
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("string1", "foo"));
nameValuePairs.add(new BasicNameValuePair("string2", "bar"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
//Check the response
if(response == null) return null;
//POST DONE
} catch(Exception ex) {
ex.printStackTrace();
}
php:
<?php
if(isset($_POST['string1'])) {
//Do stuff with the $_POST
} else {
//Nothing to see here
}
?>
請到通過以下鏈接:http://stackoverflow.com/questions/3027066/how-to-send-a- JSON-對象過請求與 - 機器人 – Basil