gpt4 book ai didi

java - 如何从 PHP 服务器上的 android 获取值

转载 作者:行者123 更新时间:2023-12-01 13:16:21 27 4
gpt4 key购买 nike

public void postData() {  
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost/howdy/welcome.php");

try {

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("name", "rxn"));
nameValuePairs.add(new BasicNameValuePair("id", "b15803"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
System.out.println("data posted, status = " + status);

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}





}

这是我将名称和 ID 发布到本地服务器的代码。现在接受这些参数的 php 代码是什么,以便我能够存储在变量中并在网页上回显。提前致谢

最佳答案

您将此数据作为 POST 请求发送,因此另一端只需使用 $_POST 变量即可获取它。这是一个例子:

$name = $_POST['name'];
$id = $_POST['id'];

echo "Hi, my name is $name and my id is $id\n";

关于java - 如何从 PHP 服务器上的 android 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22437545/

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