我正在製作一個android應用並在模擬器上運行它。發送http發佈請求時,服務器上的所有發佈參數都爲空。這是Android應用代碼:發送一個http發佈請求不起作用
public void run() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(page);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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);
InputStreamReader inreader = new InputStreamReader(response.getEntity().getContent());
BufferedReader reader = new BufferedReader(inreader);
String line = "";
while((line = reader.readLine()) != null){
System.out.println(line);
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
}
而且這是在服務器上的代碼:
<?php
print_r($_POST);
?>
它返回時,我在模擬器上運行一個空的PHP數組。
看起來您需要$ _POST - >示例的標識符:$ _POST ['item_that_was_posted_here'] – Rob
您是否收到任何錯誤? –
您是否在清單文件中提供Internet權限? – Syn3sthete