Android HTTPPost Null

时间:2011-04-26 16:59:11

标签: php android http-post

我正试图从我的Android手机上将字符串发布到我的网络服务器上的php文件中。我能够建立与文件的连接,因为我可以检索它打印的内容。我遇到的问题是发送POST变量,它似乎一直是null(我现在正在测试程序,并发回POST变量的内容)。以下是相关代码:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(HTTP://WWW....PHP FILE ADDRESS);
    try{
                // the data to send
                 List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                 nameValuePairs.add(new BasicNameValuePair("RoomName", "HELLO"));//params[1]
                // http post
                 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
                 HttpResponse response = httpclient.execute(httppost);

                 HttpEntity entity = response.getEntity();
                 InputStream is = entity.getContent();

我的PHP代码(目前)如下:

  $roomname = $_POST['RoomName'];
  $returnArray[] = array("LoggedIn" => $roomname);
  print_r(json_encode($returnArray));

过去一周我一直在寻找论坛,所有的httppost示例几乎完全遵循这一点。我很感激您愿意给予的任何帮助。非常感谢

1 个答案:

答案 0 :(得分:0)

好吧,试试$ _REQUEST $ _POST。