<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableURLRequest/setValue(_:forHTTPHeaderField:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableURLRequest(im)setValue:forHTTPHeaderField:"
  },
  "title" : "setValue(_:forHTTPHeaderField:)"
}
-->

# setValue(_:forHTTPHeaderField:)

Sets a value for the header field.

```
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

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`](/documentation/Foundation/NSURLRequest#Reserved-HTTP-headers).

## See Also

[`-  valueForHTTPHeaderField:`](/documentation/Foundation/NSURLRequest/value(forHTTPHeaderField:))

Returns the value of the specified HTTP header field.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)