1

在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);
4

1 回答 1

0

尝试这个

HttpPost post = new HttpPost(url1);
StringEntity stringEntity = new StringEntity(json);
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
post.setEntity(stringEntity);
response = client.execute(post);
于 2013-08-21T09:39:02.310 回答