在Android中,当我使用httppost方法将数据发布到webservice作为回报时,我应该得到webservice的响应。但我得到回应
错误请求(无效的标头名称)
.作为回应,我收到了这个错误。
HttpClient httpClient = new DefaultHttpClient();
// HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),
// 10000);
HttpPost httpPost = new HttpPost(url1);
Log.e("HTTPPOST", httpPost.toString());
httpPost.setHeader("content-type",
"application/json; charset= utf-8");
httpPost.setHeader("Accept", "application/json");
// Log.e("HTTPPOST", httpPost.toString());
JSONObject data = new JSONObject();
try {
data.put("URL", str);
StringEntity entity = new StringEntity(data
.toString(), HTTP.UTF_8);
entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(entity);
try {
HttpResponse response = httpClient
.execute(httpPost);
// Log.e("dsfsdfsadf",response);
String responseBody = EntityUtils
.toString(response.getEntity());
Log.i("Server Response 1: ", responseBody);