Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java从Orange消息Api获取AccessToken_Java_Sms_Orange Api - Fatal编程技术网

如何使用Java从Orange消息Api获取AccessToken

如何使用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

我正在尝试用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 = (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";
(适度在适度之前试着理解一个答案可能会很好)