簡體   English   中英

無法通過發布請求發送JSON Raw

[英]Unable to send JSON Raw via Post Request

這是我的POST Json,我必須從android應用程序傳遞數據,任何人都可以幫助我

{  
   "book":{  
      "details":{  
         "detail":[  
            {  
               "title":"Ms"
            }
         ]
      },
      "contact_detail":{  
         "mobile_number":"9888888888"
      }
   },
   "origin_id":"134"
}

和我的Android代碼

@Override
    protected Void doInBackground(Void... params) {
        HttpURLConnection urlConnection=null;
        String json = null;
        try {
            HttpResponse response;
            JSONObject jsonObject = new JSONObject();
             jsonObject.accumulate("origin_id", "134");
            jsonObject.accumulate("mobile_number", "9888888888");

            jsonObject.accumulate("title", "Ms");
            json = jsonObject.toString();
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new StringEntity(json, "UTF-8"));
            httpPost.setHeader("Content-Type", "application/json");
            httpPost.addHeader("Accept-Encoding", "gzip");
           // httpPost.setHeader("Accept-Language", "en-US");
            response = httpClient.execute(httpPost);
            String sresponse = response.getEntity().toString();
            Log.w("QueingSystem", json);
            Log.w("QueingSystem", sresponse);
            Log.w("QueingSystem", EntityUtils.toString(response.getEntity()));
        }
        catch (Exception e) {
            Log.d("InputStream", e.getLocalizedMessage());

        } finally {
    /* nothing to do here */
        }
        return null;
    }

收到錯誤輸出{“ response”:{“ code”:400,“ message”:“無效的Json”}}無法獲得任何幫助,請幫助我

我驗證了您提供的JSON,它是正確的。

我查看了您在POST上的編碼,但是您是否通過或正在使用實際的JSON

〜jsonObject.accumulate(“ origin_id”,“ 134”); jsonObject.accumulate(“ mobile_number”,“ 9888888888”);

但是,您的方法可以簡化。 如果在EndPoints之前和之后插入log語句,它將查明哪些Java對象為您提供了哪些值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM