gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:09:11 25 4
gpt4 key购买 nike

这是我用来发送到我网站上的 php 文件的 android 代码。还修改了android list 文件。

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

这是我用于从 android 接收数据的 php 脚本。但我的问题是,当我在 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(...)

关于java - 使用http将数据从android发送到php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com