I would like to do a request with this statement of curl:
curl -u Username:Password -d "auth" https://.../.../...
I want create a connection to battle.net (Blizzard developer's API) but I don't know hot to implement -d
. I hope someone can help me. Sry for my bad english. I am new in this community.
public static void main(String[] args) throws IOException {
String user = "...";
String pwd = "...";
try {
URL url = new URL ("https://(battle.net)");
String encoding = Base64.getEncoder().encodeToString((user + ":" + pwd).getBytes("UTF-8"));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty ("authorization_code", encoding);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in =
new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch(Exception e) {
e.printStackTrace();
}
}
ERROR:
java.io.IOException: Server returned HTTP response code: 401 for URL: "https://(battle.net)"
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at gnfcxfg.asd.main(asd.java:28)