Android的HTTPPost空 [英] Android HTTPPost Null

查看:176
本文介绍了Android的HTTPPost空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Andr​​oid手机发布一个字符串到PHP文件我的Web服务器上。我能够建立到文件的连接,我可以取回它所打印。我有在发送POST变量,它不断地似乎是空(我现在正在测​​试的程序,发回POST变量是什么)的问题。下面是相关code:

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();

我的PHP code是(目前)如下:

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

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

我一直在寻找的论坛在过去的一周,所有的httppost例子遵循这个几乎一模一样。我想AP preciate,你是愿意给任何帮助。非常感谢

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

Well, try $_REQUEST in place $_POST.

这篇关于Android的HTTPPost空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆