如何使用Java从Orange消息Api获取AccessToken
我正在尝试用Java生成带有的令牌 到目前为止,我在获取如何使用Java从Orange消息Api获取AccessToken,java,sms,orange-api,Java,Sms,Orange Api,我正在尝试用Java生成带有的令牌 到目前为止,我在获取postdata时发现了以下错误file not found异常或error 411 这是我的代码: String url = "https://api.orange.com/oauth/token"; try { URL obj = new URL(url); String postdata = "grant_type=client_credentials"; HttpURLConnection con
postdata
时发现了以下错误file not found
异常或error 411
这是我的代码:
String url = "https://api.orange.com/oauth/token";
try {
URL obj = new URL(url);
String postdata = "grant_type=client_credentials";
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String credentials = "client-id" + ":" + "client-secret";
String base64EncodedCreds = Base64.getEncoder().encodeToString(credentials.getBytes());
con.setRequestProperty ("Authorization", "Basic " + base64EncodedCreds);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(postdata);
wr.flush();
wr.close();
ByteArrayOutputStream rspBuff = new ByteArrayOutputStream();
InputStream rspStream = con.getInputStream();
int c;
while ((c = rspStream.read())>0){
rspBuff.write(c);
}
} catch (Exception e) {
e.printStackTrace();
}
}
您在代码中用于请求令牌的URL错误,您忘记了v2
String url = "https://api.orange.com/oauth/v2/token";
(适度在适度之前试着理解一个答案可能会很好)