我是 android 新手,我有一个关于名称值对的问题,我有点困惑。例如,我尝试发布到以下示例并使用端点获取响应代码:/account/create/bank-id?ssn=SSN&name=NAME&email=EMAIL。我会编辑需要编辑以下内容:bank-id、SSN、NAME 和 EMAIL。眼下。我正在考虑(到目前为止没有运气,没有打印响应代码,所以我不知道我现在做错了什么,请回复):
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xx.xxx.xxx/account/create/");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("bank-id", "12345"));
nameValuePairs.add(new BasicNameValuePair("ssn", "451"));
nameValuePairs.add(new BasicNameValuePair("name", "kitty"));
nameValuePairs.add(new BasicNameValuePair("name", "kitty"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Log.d("Http Post Response:", response.toString());
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}