【问题标题】:$_POST is empty after making a post request from android从 android 发出 post 请求后 $_POST 为空
【发布时间】:2014-06-22 13:00:40
【问题描述】:

我正在尝试使用 android 和 php 登录系统。我可以从 url 读取响应,但 $_POST 数组总是空的。我是新手,所以任何帮助都将不胜感激。这是我的 android 代码。

protected String doInBackground(String... params) {     
        try {
            String link="http://10.0.2.2/monitorhealth";

            HttpClient httpClinet=new DefaultHttpClient();
            HttpPost httppost=new HttpPost(link);

            List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("username","X"));
            nameValuePairs.add(new BasicNameValuePair("password","Y"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response=httpClinet.execute(httppost);

            InputStream inputStream=response.getEntity().getContent();
            InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
            BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
            StringBuilder sb=new StringBuilder();
            String line;

            while((line=bufferedReader.readLine())!=null){
                sb.append(line);

            }
            Log.e("Response","Received:"+sb.toString());
            return sb.toString();
}

在 index.php 中只有一条语句 $_POST['username] 显示错误。

【问题讨论】:

  • 你能给我们看看 index.php 的内容吗?

标签: php android httprequest


【解决方案1】:

发现错误。只需要更正网址。替换为

<code>
String link="http://10.0.2.2/monitorhealth/index.php";
</code>

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 2016-10-07
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2018-07-09
    • 2012-08-15
    • 2016-08-29
    • 1970-01-01
    相关资源
    最近更新 更多