What is the proper way of setting headers in a URLConnection?

前端 未结 3 837
粉色の甜心
粉色の甜心 2020-12-10 01:32

My code is like the following:

URLConnection cnx = address.openConnection();
cnx.setAllowUserInteraction(false);         
cnx.setDoOutput(true);
cnx.addReque         


        
3条回答
  •  半阙折子戏
    2020-12-10 02:33

    To answer the question, the code is correct. The moment getInputStream(), an HTTP get is sent to the target server.

    A side-note on user-agent, if you don't set it, URLConnection will send the default one anyway, which is:

    User-Agent: Java/1.6.0_24 (varies depending on your java version)
    

提交回复
热议问题