Function

CFHTTPMessageAddAuthentication

Adds authentication information to a request.

Declaration

Boolean CFHTTPMessageAddAuthentication(CFHTTPMessageRef request, CFHTTPMessageRef authenticationFailureResponse, CFStringRef username, CFStringRef password, CFStringRef authenticationScheme, Boolean forProxy);

Parameters

request

The message to which to add authentication information.

authenticationFailureResponse

The response message that contains authentication failure information.

username

The username to add to the request.

password

The password to add to the request.

authenticationScheme

The authentication scheme to use (kCFHTTPAuthenticationSchemeBasic, kCFHTTPAuthenticationSchemeNegotiate, kCFHTTPAuthenticationSchemeNTLM, or kCFHTTPAuthenticationSchemeDigest), or pass NULL to use the strongest supported authentication scheme provided in the authenticationFailureResponse parameter.

forProxy

A flag indicating whether the authentication data that is being added is for a proxy’s use (TRUE) or for a remote server’s use (FALSE). If the error code provided by the authenticationFailureResponse parameter is 407, set forProxy to TRUE. If the error code is 401, set forProxy to FALSE.

Return Value

TRUE if the authentication information was successfully added, otherwise FALSE.

Discussion

This function adds the authentication information specified by the username, password, authenticationScheme, and forProxy parameters to the specified request message. The message referred to by the authenticationFailureResponse parameter typically contains a 401 or a 407 error code.

This function is best suited for sending a single request to the server. If you need to send multiple requests, use CFHTTPMessageApplyCredentials.

See Also

HTTP Messages

CFHTTPMessageRef

An opaque reference representing an HTTP message.

CFHTTPMessageAppendBytes

Appends data to a CFHTTPMessage object.

CFHTTPMessageApplyCredentialDictionary

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

CFHTTPMessageApplyCredentials

Performs the authentication method specified by a CFHTTPAuthentication object.

CFHTTPMessageCopyAllHeaderFields

Gets all header fields from a CFHTTPMessage object.

CFHTTPMessageCopyBody

Gets the body from a CFHTTPMessage object.

CFHTTPMessageCopyHeaderFieldValue

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

CFHTTPMessageCopyRequestMethod

Gets the request method from a CFHTTPMessage object.

CFHTTPMessageCopyRequestURL

Gets the URL from a CFHTTPMessage object.

CFHTTPMessageCopyResponseStatusLine

Gets the status line from a CFHTTPMessage object.

CFHTTPMessageCopySerializedMessage

Serializes a CFHTTPMessage object.

CFHTTPMessageCopyVersion

Gets the HTTP version from a CFHTTPMessage object.

CFHTTPMessageCreateCopy

Gets a copy of a CFHTTPMessage object.

CFHTTPMessageCreateEmpty

Creates and returns a new, empty CFHTTPMessage object.

CFHTTPMessageCreateRequest

Creates and returns a CFHTTPMessage object for an HTTP request.

CFHTTPMessageCreateResponse

Creates and returns a CFHTTPMessage object for an HTTP response.

CFHTTPMessageGetResponseStatusCode

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

CFHTTPMessageGetTypeID

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

CFHTTPMessageIsHeaderComplete

Determines whether a message header is complete.

CFHTTPMessageIsRequest

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

CFHTTPMessageSetBody

Sets the body of a CFHTTPMessage object.

CFHTTPMessageSetHeaderFieldValue

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

kCFHTTPVersion1_0

Specifies HTTP version 1.0.

kCFHTTPVersion1_1

Specifies HTTP version 1.1.