views:

267

answers:

1

Hi,

I'm using the Sun API HttpsURLConnection class, and have been trying for a day now to get it to send a simple request:

URL url = new URL("https://thirdpartyserver.com/somelocation");
connection = (HttpsURLConnection)url.openConnection();

connection.setDoOutput(true);
connection.setRequestMethod("POST");

if (doAuthorization) {
    Base64Converter converter = new Base64Converter();
    connection.setRequestProperty("Authorization", 
               "Basic " +  converter.encode("username:password"));
}

OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write("param1=100&param2=hello");
writer.flush();

writer.close();

I keep getting 401 from the third part server. When I look at the connection through the debugger, the method shows up as GET even though I set it to POST; the collection of request properties shows up as null.

If I print the values out, the method shows up as POST, but the request parameters collection is still empty.

I would love to be able to print the request and understand what's going on, but I could not figure out how to print the content of an output buffer.

Any ideas?

Thanks!

ES

A: 

So I resolved the issue with the third party server (something on their end), but two questions remain:

  1. Has anyone ever encountered a guess where the debugger showed inaccurate values? Or is this something else?

  2. Is there any way to print the entire contents of a javax.net.ssl.httpsurlconnection?

Thanks!

ES

related questions