【发布时间】:2014-03-16 13:38:15
【问题描述】:
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 代码将是什么,以便我能够存储在变量中并在网页上回显。 提前致谢
【问题讨论】:
标签: java php android http httpclient