The difference between setting the NSMutableURLRequest header and adding one

I was wondering what the difference is between setting the header value and adding the header value in NSMutableURLRequest. That sounds obvious, but for example, can't you just use addValue every time? Will setting a header that does not exist produce an error? Will adding a header, when it already exists in the request, overwrite the existing value?

Example

let request.NSMutableURLRequest(URL: NSURL(string: "someURL")!) 
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
...
+4
source share
1 answer

I think the discussion in the Apple white paper is quite clear:

addValue

. , . HTTP .

setValue

. .


setValue . addValue

+7

Source: https://habr.com/ru/post/1584173/


All Articles