1

Android では、httppost メソッドを使用してデータを webservice に投稿すると、webservice から応答が返されます。しかし、私は次のように応答します

Bad Request (無効なヘッダー名)

.

応答本文で、このエラーが発生しています。

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 に答える