简体   繁体   中英

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{
                // 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

好吧,尝试$ _REQUEST到位$ _POST。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM