The program does a http post with basic authorization just fine but when the post is complete the page is redirected to a success page. The redirect failes due to 401 authorization failed.
final URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Authorization", "basic " +base64);
wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
The line
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
fails due to 401 authorization failed…
I have also tried adding
conn.setRequestProperty("Authorization", "basic " +base64);
after
wr.flush();
I get the error of "Already connected". Evidently the authorization that I set doesn't follow over to the redirect. Any solutions to this problem is greatly appreciated.
Best Answer
You have 2 options you can try:
setDefaultRequestProperty
(see http://download.oracle.com/javase/1.5.0/docs/api/java/net/URLConnection.html#setDefaultRequestProperty%28java.lang.String,%20java.lang.String%29) method to set the Authorization header.