SocketTools .NET Edition

HttpClient.SetHeader Method 

Set the value of a request header field.

[Visual Basic]
Public Function SetHeader( _
   ByVal headerName As String, _
   ByVal headerValue As String _
) As Boolean
[C#]
public bool SetHeader(
   string headerName,
   string headerValue
);

Parameters

headerName
A string that specifies the name of the request header.
headerValue
A string that specifies the value associated with the request header. If this argument is set to an empty string, the request header is and its previous value are deleted.

Return Value

This method returns a Boolean value. If the method succeeds, the return value is true. If the method fails, the return value is false. To get extended error information, check the value of the LastError property.

Remarks

The SetHeader method is used to set the values of specific fields in the HTTP request header. This method should be called before the client has requested the resource.

Some headers are generated by methods that send resource requests. Some of these are supplied by the requesting methods only if the application has not previously defined the header. For others, the requesting method overrides what the application may have defined. The affected headers include:

Header Description
Accept This header field specifies the type of content that the client will accept. By default, all content types will be accepted by the client.
Authorization This header field specifies the authentication information required to access the resource. By default, this header field is only defined if the client specifies a username and password.
Connection This header field is automatically defined based on the value specified by the KeepAlive property.
Content-Length This header field is automatically defined when data is being posted to the server or a file is being uploaded.
Content-Type This header field is automatically defined when data is being posted to the server or a file is being uploaded.
Host This header field defines the hostname of the server. By default, the hostname provided to the Connect method will be used.
Proxy-Authorization This header field specifies the proxy authentication information required to access the resource. By default, this header field is only defined if a proxy server has been specified, along with a username and password.

See Also

HttpClient Class | SocketTools Namespace | AddHeaders Method | GetHeader Method