connection.setRequestProperty and excplicitly writing to the urloutputstream are they same?

元气小坏坏 提交于 2019-11-30 19:02:38

No, it is not. The URLConnection#setRequestProperty() sets a request header. For HTTP requests you can find all possible headers here.

The writer just writes the request body. In case of POST with urlencoded content, you'd normally write the query string into the request body instead of appending it to the request URI like as in GET.

That said, connection.setDoOutput(true); already implicitly sets the request method to POST in case of a HTTP URI (because it's implicitly required to write to the request body then), so doing an connection.setRequestMethod("POST"); afterwards is unnecessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!