java – URLConnection setRequestProperty vs addRequestProperty
Let me say I'm talking about HTTP to a web server. I will accept HTML or text, but I prefer HTML In other words, the title should say (I think!)
Accept: text / HTML, text /*
I use Java, so I have a urlconnection Should I use it
myUrlConnction.setRequestProperty("Accept","text/html"); myUrlConnction.addRequestProperty("Accept","text/*");
or
myUrlConnction.setRequestProperty("Accept","text/html,text/*");
Or is it equivalent?
Generally speaking, most of the third-party code I see doesn't seem to worry about the sorting or multiple values of these header files, so I want to know how to work in the end
Solution
The first snippet will result in two accept headers, while the second snippet will give two selectors an accept header
They are actually equivalent
The specification also states that more specific media coverage has priority, so both will produce your expected behavior
If you must specify multiple media ranges and they are equally specific, you can add the Q parameter
Source: http 1.1 specification( http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html ):