URLConnection setRequestProperty vs addRequestProperty

后端 未结 2 398
长发绾君心
长发绾君心 2020-12-31 05:50

Lets say I\'m talking HTTP to a web server, and I will Accept html or text, but prefer html. In other words, the header should say (I think!)

Accept: text/html, tex

2条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 06:43

    The basic difference between setRequestProperty and addRequestProperty is:-

    1. setRequestProperty>> Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

    2. addRequestProperty >> Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.

    For more information browse the api doc

提交回复
热议问题