作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
我是一名优秀的程序员,十分优秀!