tags:

views:

58

answers:

1

Hi All,

i am making http connection using

URL urlToConnect = new URL ("http://www.xyz.com");
HttpURLConnection connection = ( HttpURLConnection )  urlToConnect.openConnection();

I need to set the following property ,i am doing it like

connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("user-agent", USER_AGENT);
connection.setRequestProperty("Content-Type", "application/xml");
connection.setRequestProperty("Accept", "application/xml");
connection.setRequestProperty("http_code", "200");
connection.setRequestProperty("USERNAME", "test");
connection.setRequestProperty("PASSWORD", "test");

Is it the right way to set all these data?

+1  A: 

Yes, what you are doing is perfect.

Francis Upton
But i am getting response 400 always from the server,i also want to know how to set username and password while making connection ? i am using setrequestproperty method.
sarah
and the connection uses https,so i am setting port and host also
sarah
Francis Upton
no username and pwd does not come with url it has to be set in request ,ya i am using https only
sarah
Maybe you can run wireshark to capture what the request actually is? And you can post that (changing things as required for security) A 400 indicates something is really messed up which is not usual when making an HTTP request.
Francis Upton
Oh, and are you sure they are expecting an HTTP POST? Perhaps they are expecting an HTTP GET instead. If they do want a post, are you actually sending the data (calling getOutputStream() and writing something to the request?)
Francis Upton