Creates and returns a CFHTTPMessage object for an HTTP request.


func CFHTTPMessageCreateRequest(_ alloc: CFAllocator?, _ requestMethod: CFString, _ url: CFURL, _ httpVersion: CFString) -> Unmanaged<CFHTTPMessage>



The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.


The request method for the request. Use any of the request methods allowed by the HTTP version specified by httpVersion.


The URL to which the request will be sent.


The HTTP version for this message. Pass kCFHTTPVersion1_0 or kCFHTTPVersion1_1.

Return Value

A new CFHTTPMessage object, or NULL if there was a problem creating the object. Ownership follows the The Create Rule.


This function returns a CFHTTPMessage object that you can use to build an HTTP request. Continue building the request by callingCFHTTPMessageSetBody(_:_:) to set the message’s body. Call CFHTTPMessageCopyHeaderFieldValue(_:_:) to set the message’s headers.

If you are using a CFReadStream object to send the message, call CFReadStreamCreateForHTTPRequest(_:_:) to create a read stream for the request. If you are not using CFReadStream, call CFHTTPMessageCopySerializedMessage(_:) to make the message ready for transmission by serializing it.

See Also

HTTP Messages

class CFHTTPMessage

An opaque reference representing an HTTP message.

func CFHTTPMessageApplyCredentialDictionary(CFHTTPMessage, CFHTTPAuthentication, CFDictionary, UnsafeMutablePointer<CFStreamError>?) -> Bool

Use a dictionary containing authentication credentials to perform the authentication method specified by a CFHTTPAuthentication object.

func CFHTTPMessageCopyBody(CFHTTPMessage) -> Unmanaged<CFData>?

Gets the body from a CFHTTPMessage object.

func CFHTTPMessageCopyHeaderFieldValue(CFHTTPMessage, CFString) -> Unmanaged<CFString>?

Gets the value of a header field from a CFHTTPMessage object.

func CFHTTPMessageCopyRequestMethod(CFHTTPMessage) -> Unmanaged<CFString>?

Gets the request method from a CFHTTPMessage object.

func CFHTTPMessageCopyVersion(CFHTTPMessage) -> Unmanaged<CFString>

Gets the HTTP version from a CFHTTPMessage object.

func CFHTTPMessageCreateEmpty(CFAllocator?, Bool) -> Unmanaged<CFHTTPMessage>

Creates and returns a new, empty CFHTTPMessage object.

func CFHTTPMessageGetResponseStatusCode(CFHTTPMessage) -> CFIndex

Gets the status code from a CFHTTPMessage object representing an HTTP response.

func CFHTTPMessageGetTypeID() -> CFTypeID

Returns the Core Foundation type identifier for the CFHTTPMessage opaque type.

func CFHTTPMessageIsHeaderComplete(CFHTTPMessage) -> Bool

Determines whether a message header is complete.

func CFHTTPMessageIsRequest(CFHTTPMessage) -> Bool

Returns a Boolean indicating whether the HTTP message is a request or a response.

func CFHTTPMessageSetBody(CFHTTPMessage, CFData)

Sets the body of a CFHTTPMessage object.

func CFHTTPMessageSetHeaderFieldValue(CFHTTPMessage, CFString, CFString?)

Sets the value of a header field in an HTTP message.

let kCFHTTPVersion1_0: CFString

Specifies HTTP version 1.0.

let kCFHTTPVersion1_1: CFString

Specifies HTTP version 1.1.