URLConnection setRequestProperty vs addRequestProperty

后端 未结 2 411
长发绾君心
长发绾君心 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:28

    The first code snippet would result in two accept-headers while the second code snippet would give one accept-header with two selectors.

    They are in fact equivalent.

    The spec also states that the more specific media range have precedence, so both would yield your expected behavior.

    If you must specify several media ranges, and they are equally specific, you could add the q-parameter.

    Source: http 1.1 spec ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html ) :

提交回复
热议问题