---
title: "init(url:statusCode:httpVersion:headerFields:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/httpurlresponse/init(url:statuscode:httpversion:headerfields:)-21j4x"
---

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

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

## Declaration

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

Return Value An initialized HTTPURLResponse object or nil if an error occurred during initialization.
