JSON-Antwort Fehler Code 201,aber es sollte 200 in der Android-HTTP-POST

Als iam versuchen zu buchen, das Ergebnis der Bewertung der Aktivität. Nach dem Lesen der rating-Wert aus der user-ich bin dem Aufruf der webservice-thro HTTP-POST und Einstellung JSON-Objekt. Als Mein webserver authentifizieren, iam in der Lage zu überprüfen, wie gut.

Aber das eigentliche problem ist der response-code 200 aber iam-erhalten 201. Bitte schlagen Sie mich, wo iam schief geht!

Code:

        public static String sendJson(final int rating, final String url) {
    Thread t = new Thread() {
        public void run() {
            Looper.prepare(); //For Preparing Message Pool for the child
             HttpResponse response;

            //proxy
            final String PROXY = "xxx.xxx.xxx.xxx";
            //proxy host
            final HttpHost PROXY_HOST = new HttpHost(PROXY, 8080);
            HttpParams httpParameters = new BasicHttpParams();
            mHttpClient = new DefaultHttpClient(httpParameters);
            HttpConnectionParams.setConnectionTimeout(mHttpClient.getParams(),
                 10000); //Timeout Limit
            mHttpClient.getParams().setParameter(
                    ConnRoutePNames.DEFAULT_PROXY, PROXY_HOST);
            System.out.println("Sending proxy request: " + mHttpClient);
            //mHttpClient = new DefaultHttpClient();

            JSONObject json = new JSONObject();
            try {
                String reqUrl = new String(aBaseUrl + url);                  
                HttpPost post = new HttpPost(reqUrl);
                post.getParams().setParameter(
                        ConnRoutePNames.DEFAULT_PROXY, PROXY_HOST);
                post.addHeader(BasicScheme
                        .authenticate(new UsernamePasswordCredentials(
                                userName, password), "UTF-8", false));
                System.out.println("Sending Post proxy request: " + post);
                json.put("rating", rating);

                //json.put("password", pwd);
                //StringEntity se = new StringEntity( "JSON: " +json.toString());

                StringEntity se = new StringEntity(json.toString());
                System.out.println("JSON VALUE 2222 " + json.toString());
                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
                //post.setEntity(new
                //ByteArrayEntity(json.toString().getBytes("UTF8")));

                post.setEntity(se);
                response = mHttpClient.execute(post);
                /* Checking response */

                statusCode = response.getStatusLine().getStatusCode();
                System.out.println("Http Execute finish " + statusCode);

                if(statusCode==200)
                {
                    HttpEntity entity = response.getEntity();
                    String getResponseText = EntityUtils.toString(entity);
                    System.out.println(" Post Response Text from Server : "
                            + getResponseText);


                }

                if (response != null) {
                    //InputStream in = response.getEntity().getContent();
                    ////Get the data in the entity
                    //HttpEntity entity = response.getEntity();
                    //String getResponseText =
                    //EntityUtils.toString(entity);
                    //System.out.println(" Post Response Text from Server : "
                    //+ getResponseText);

                }
            } catch (Exception e) {
                e.printStackTrace();
                //createDialog("Error", "Cannot Estabilish Connection");
            }
            Looper.loop(); //Loop in the message queue
        }
    };
    t.start();
    return url;
}
InformationsquelleAutor ReachmeDroid | 2011-03-29
Schreibe einen Kommentar