ฉันกำลังทำงานกับ Uber API และพยายามเรียกรถในแซนด์บ็อกซ์ ฉันกำลังทำตามคำแนะนำ API จากที่นี่ - Uber API - คำขอ POST
StringEntity param; หรือ 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 ของฉันดูคล้ายกับตัวอย่าง Uber ที่แนะนำ .. ฉันกำลังตั้งค่าส่วนหัว JSON ด้วย - โทเค็นการอนุญาตและประเภทเนื้อหา .. ดังนั้นฉันจึงไม่แน่ใจว่าฉันขาดอะไรไป ..
มีใครเห็นบ้างไหม - ฉันทำอะไรผิด?
ขอบคุณล่วงหน้า