---
title: "setValue(_:forHTTPHeaderField:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutableurlrequest/setvalue(_:forhttpheaderfield:)"
---

# setValue(_:forHTTPHeaderField:)

Sets a value for the header field.

## Declaration

```swift
func setValue(_ value: String?, forHTTPHeaderField field: String)
```

## Parameters

- `value`: The new value for the header field. Any existing value for the field is replaced by the new value.
- `field`: The name of the header field to set. In keeping with the HTTP RFC, HTTP header field names are case insensitive.

## Discussion

Discussion Certain header fields are reserved. Do not use this method to set such headers. Specifically, there is no need for you to set the Content-Length header. See Reserved HTTP headers.

## See Also

### Related Documentation

- [value(forHTTPHeaderField:)](foundation/nsurlrequest/value(forhttpheaderfield:).md)

### Accessing header fields

- [allHTTPHeaderFields](foundation/nsmutableurlrequest/allhttpheaderfields.md)
- [addValue(_:forHTTPHeaderField:)](foundation/nsmutableurlrequest/addvalue(_:forhttpheaderfield:).md)
