<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/HTTPURLResponse/init(url:statusCode:httpVersion:headerFields:)-21j4x",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSHTTPURLResponse(im)initWithURL:statusCode:HTTPVersion:headerFields:"
  },
  "title" : "init(url:statusCode:httpVersion:headerFields:)"
}
-->

# init(url:statusCode:httpVersion:headerFields:)

Initializes an HTTP URL response object with a status code, protocol version, and response headers.

```
init?(url: URL, statusCode: Int, httpVersion HTTPVersion: String?, headerFields: [String : String]?)
```

## Parameters

`url`

The URL from which the response was generated.

`statusCode`

The HTTP status code to return (`404`, for example). See [RFC 2616](http://www.ietf.org/rfc/rfc2616.txt) for details.

`HTTPVersion`

The version of the HTTP response as returned by the server. This is typically represented as “HTTP/1.1”.

`headerFields`

A dictionary representing the keys and values from the server’s response header.

## Return Value

An initialized [`HTTPURLResponse`](/documentation/Foundation/HTTPURLResponse) object or `nil` if an error occurred during initialization.

---

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)