sarah
sarah

Reputation: 2397

How to set request propert while making http connection?

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?

Upvotes: 0

Views: 1531

Answers (1)

Francis Upton IV
Francis Upton IV

Reputation: 19443

Yes, what you are doing is perfect.

Upvotes: 1

Related Questions