2016-10-04 83 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