【发布时间】:2012-07-10 10:47:30
【问题描述】:
我正在尝试从 Android 联系 API
我找到了这个示例代码...
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
我的问题是,我如何查看回复以确保收到回复?有没有办法添加 API 密钥?
另外,“yoursite.com”是否必须是 PHP 文件?
【问题讨论】:
-
服务器不必在 php 中使用任何你想要的服务器端。我们使用 python 和 Django。
标签: java php android api http-post