我是android的新手,我有一个关于名称值对的问题,我有点困惑。例如,我试图发布到以下示例并使用端点获取响应代码: /帐号/创建/银行-ID SSN = SSN和放大器;名称=名称及放大器;电子邮件=电子邮件。我会编辑编辑以下内容的需要:bank-id,SSN,NAME和EMAIL。在这一刻。我正在思考(到目前为止没有运气,没有反应代码正在打印所以我不知道我现在做错了什么,对任何回复都是ty):
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
}
}