开发者

How to set request propert while making http connection?

开发者 https://www.devze.com 2022-12-13 23:46 出处:网络
i am making http connection using URL urlToConnect = new URL (\"http://www.xyz.com\"); HttpURLConnection connection = ( HttpURLConnection )urlToConnect.openConnection();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消