使用 Java,进行简单的“delivery_quotes”调用以进行测试,返回 HTTP 响应代码 - 403
下面是代码:
String api_key = Base64.getEncoder().encodeToString("95xxxxx1-xxxx-44h1-8961-904xxx024fb:".getBytes("utf-8"));
String postData = "pickup_address=" + java.net.URLEncoder.encode("20 McAllister St, San Francisco, CA", "UTF-8") + "&" +
"dropoff_address=" + java.net.URLEncoder.encode("101 Market St, San Francisco, CA", "UTF-8");
String apiURL = "https://api.postmates.com/v1/customers/cus_LxxxxRaHNT_yqV/delivery_quotes";
URL myurl = new URL(apiURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Authorization", "Basic " + api_key);
OutputStream os = con.getOutputStream();
os.write(postData.getBytes());
InputStream istream = con.getInputStream();
int ch;
while((ch=istream.read()) != -1)
{
System.out.print((char)ch);
}
线程“主”java.io.IOException 中的异常:服务器返回 HTTP 响应代码:URL 的 403:https ://api.postmates.com/v1/customers/cus_LBxxxxxxNT_yqV/delivery_quotes
我使用的客户 ID 和测试 API 密钥是正确的。任何帮助!