我知道关于这个主题还有其他帖子,但我一直试图解决这个问题一个星期但无济于事。
这是我通过android连接到服务器的代码:
public String postQuery(String queryString, String jsonData, String [][]jsonDataArray){
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://myapp.com/app.php");
String tempLine = "";
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("a_token", "SDFSDF"));
nameValuePairs.add(new BasicNameValuePair("d_id", "S34S"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
tempLine = tempLine + line;
}
} catch (IOException e) {
e.printStackTrace();
}
return tempLine;
}
我服务器上的代码如下所示:
Token: <?php echo $_POST["a_token"]; ?><br />
ID: <?php echo $_POST["d_id"]; ?><br />
Let's print out the entire Post:
<?php print_r($_POST); ?>
然后我的 android 活动调用以下内容:
String result = serverClient.postQuery(query, jsonData2, jsonData);
Toast.makeText(InterestsActivity.this, "" + result, Toast.LENGTH_SHORT).show();
然后在我的 android 设备上显示的是:
Token:</br>ID:</br>Let's print out the entire Post: Array()
谁能弄清楚为什么我的 Post 数据没有被传输到服务器?提前致谢