开发者

Android HTTPPost Null

I am trying to post a string to a php file on my web server from my android phone. I am able to establish a connection to the file, as I can retrieve what it prints. The problem I am having is sending the POST variable, which continually seems to be null(I am testing the program now, and sending back what the POST variable is). Here is the relevant code:

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(HTTP://WWW....PHP FILE ADDRESS);
    try开发者_Python百科{
                // 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();

My PHP code is (at the moment) as follows:

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

I have been looking at forums for the past week, and all the httppost examples follow this almost exactly. I would appreciate any help that you are willing to give. Thanks a lot


Well, try $_REQUEST in place $_POST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜