Reputation: 4290
let request = NSMutableURLRequest(URL: url)
request.addValue("application/json", forHTTPHeaderField: "Accept")
So I have this piece of code and I'm struggling to understand what the addValue method does. I've read online about requests and HTTPHeaderFields but I still can't see to grasp the concept. Would anyone be able to shed some light on this?
Upvotes: 0
Views: 1014
Reputation: 38843
The addValue
adds an HTTP header to the receiver’s HTTP header dictionary.
This method provides the ability to add values to header fields incrementally. If a value was previously set for the specified field, the supplied value is appended to the existing value using the appropriate field delimiter. In the case of HTTP, the delimiter is a comma.
Update
HTTP header fields provide required information about the request or response, or about the object sent in the message body
You have added "Accept" in your addValue and the Accept request-header field can be used to specify certain media types which are acceptable for the response.
Upvotes: 2