我需要通过 HTTP POST 向服务发送一些值。发送的参数之一必须包含空格。它是“关键”nvp。但是该服务总是返回一条不成功的消息,只要我添加一个值,它就会起作用。
现在这是一个问题,当通过 iphone 设备向同一服务完成请求时,它在发送 BLANKS 时工作得很好,我是否在我的请求中遗漏了一些内容以允许通过 NameVauePair 发送空白值?
这是我的 NaveValuePair
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("id","1"));
nameValuePairs.add(new BasicNameValuePair("uId",android_id));
nameValuePairs.add(new BasicNameValuePair("Key", " ")); // This value must be BLANKS
nameValuePairs.add(new BasicNameValuePair("Rate","0"));
nameValuePairs.add(new BasicNameValuePair("Notes", notes));
这是我的 POST 请求
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(context.getResources()
.getString(R.string.url_event_rating));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response
.getEntity());
} catch (ClientProtocolException e) {
Log.d("ClientProtocolException", e.getMessage());
} catch (IOException e) {
Log.d("IOException", e.getMessage());
}