我正在尝试发送HttpPost
请求,据我了解,为此,您可以这样做:
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(uri[0]);
try {
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
nvp.add(new BasicNameValuePair("{\"UserName\"", "\"michigan\""));
nvp.add(new BasicNameValuePair("\"Password\"", "\"fanaddicts\""));
nvp.add(new BasicNameValuePair("\"DeviceHarwareId\"", "\"NW58xfxz/w+jCiI3E592degUCL4=\""));
nvp.add(new BasicNameValuePair("\"DeviceTypeId\"", "\"1\"}"));
post.setEntity(new UrlEncodedFormEntity(nvp));
response = httpClient.execute(post);
Log.i("Feed Response", "Feed: " + response.getStatusLine().getStatusCode());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我遇到的问题是实体看起来像这样:
[{"UserName"="michigan", "Password"="fanaddicts", "DeviceHarwareId"="NW58xfxz/w+jCiI3E592degUCL4=", "DeviceTypeId"="1}]
但是由于服务器的设置方式,我需要它看起来像这样:
[{"UserName":"michigan", "Password":"fanaddicts", "DeviceHarwareId":"NW58xfxz/w+jCiI3E592degUCL4=", "DeviceTypeId":"1}]
您会注意到,不是等号 (=) 符号,而是冒号 (:) 分隔键/值对。
我的问题是:我该如何解决这个问题?