I am trying to generate token with Orange SMS API with Java.
So far I've got the following errors file not found
exceptions, or error 411
when I take postdata
.
Here is my code:
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();
}
}