繁体   English   中英

使用http将数据从android发送到php

[英]Sending data from android to php using http

这是我以前发送到网站上php文件中的android代码。 还修改了android清单文件。

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
        nameValuePairs.add(new BasicNameValuePair("number", "5556"));
        nameValuePairs.add(new BasicNameValuePair("password",password));
        nameValuePairs.add(new BasicNameValuePair("token",token));

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://futuretime.in/post.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);

这是我的php脚本,用于从android接收数据。 但是我的问题是,当我在php中打印数据时,它没有显示任何值。

        <?php 
          $number= $_POST['number'];
          $password = $_POST['password'];
          $token   = $_POST['token'];
          echo $number;
        ?>

您可以尝试使用Ion https://github.com/koush/ion ,这是一个进行http请求的好库。 是一个简单的示例。请查看项目站点以获取更多示例和Wiki。

    Ion.with(getContext(), "https://koush.clockworkmod.com/test/echo")
   .setBodyParameter("goop", "noop")
   .setBodyParameter("foo", "bar")
   .asString()
   .setCallback(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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