我正在將curl命令轉換爲Java時遇到問題。下面是我的捲曲將Curl命令轉換爲Java時的響應403
curl https://api.XXXX.com/authorizations \
-u john:doe -d '' \
-H 'Accept: application/vnd.drivr.v2+json' \
-H 'Content-type: application/json'
,我已經用這個試過相當於Java這樣直
String stringUrl = "https://api.XXXX.com/authorizations";
URL url = new URL(stringUrl);
URLConnection uc = url.openConnection();
String userpass = "john" + ":" + "doe";
//String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8"));
uc.setRequestProperty("Authorization", basicAuth);
uc.setRequestProperty("Accept", "application/vnd.drivr.v2+json");
uc.setRequestProperty("Content-type", "application/json");
System.out.println("url is: "+uc.getURL().toString()+" "+basicAuth);
InputStream inputStreamReader = uc.getInputStream();
它已經快2天。它總是給我403迴應。我不確定我會在哪裏出錯。任何幫助,將不勝感激。謝謝。