使用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);
}
线程中的异常" main" java.io.IOException:服务器返回HTTP响应代码:403为URL:https://api.postmates.com/v1/customers/cus_LBxxxxxxNT_yqV/delivery_quotes
我使用的客户ID和测试API密钥是正确的。任何帮助!
答案 0 :(得分:0)
这对我有用: