2016-10-04 82 views
1

我正在優步API,並試圖請求騎在沙箱。我從這裏獲得API指南 - Uber API - POST Request優步API - 請求騎在沙箱 - 接收錯誤:無效的請求 - validation_failed

StringEntity param; OR JSON看起來如下:

{ 
"product_id": "3145c334-25c6-462d-a2f5-70c38a165746", 
"start_latitude": 41.2237329, 
"start_longitude ": -73.2304860, 
"end_latitude": 41.7220050, 
"end_longitude": -73.3159659 
} 

Java代碼樣子:

String url = "https://sandbox-api.uber.com/v1/requests"; 
    HttpPost httpPostRequest = new HttpPost(url); 
    httpPostRequest.setHeader("Authorization", "Bearer " + accessTokenModel.getAccess_token()); 
    httpPostRequest.setHeader("Content-Type", "application/json"); 
    httpPostRequest.setEntity(param); 
    HttpResponse httpResponse = client.execute(httpPostRequest); 

    response.getWriter().println("Status Code: " + httpResponse.getStatusLine().getStatusCode()); 

    br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); 

    line = line1 = ""; 
    while ((line = br.readLine()) != null) { 
      response.getWriter().println(line); 
      line1 = line1 + line; 
    } 

我得到,狀態代碼:422 和錯誤說:

{"fields":{"":"Both start_latitude and start_longitude or start_place_id are required."},"message":"Invalid request","code":"validation_failed"} 

我的JSON看起來類似於建議的優步示例..我也設置JSON頭與 - 授權令牌和內容類型..所以不知道我錯過了什麼..

任何人都可以發現 - 我做錯了什麼?

預先感謝您

回答

2

有一個空白字符追加到start_longitude字段名稱:

"start_longitude " 
       ^remove this space character 
+0

感謝亞歷克斯 - 就是這樣。 – Jagdish