httppost安卓问题

时间:2012-08-20 17:16:38

标签: android http-post

我知道这个话题还有其他帖子,但我一直在努力解决这个问题一周,但没有用。

这是我通过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数据没有传输到服务器?提前致谢

0 个答案:

没有答案