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"开发者_JS百科, "test");
connection.setRequestProperty("PASSWORD", "test");
Is it the right way to set all these data?
Yes, what you are doing is perfect.
精彩评论