CHttpClient::SetDefaultUserAgent Method  
 
INT SetDefaultUserAgent(
  LPCTSTR lpszUserAgent  
);

The SetDefaultUserAgent method sets the default user agent string which is included with all requests.

Parameters

lpszUserAgent
A null-terminated string which specifies the new default user agent string. If this parameter is NULL or an empty string, the client will revert to using the default user agent string defined when the library was first initialized.

Return Value

If the method succeeds, the return value is the number of characters copied into the string buffer. If the method fails, the return value is HTTP_ERROR. To get extended error information, call HttpGetLastError.

Remarks

The SetDefaultUserAgent method changes the default user agent string which is included with each request made by the client. This default value is global and changing it will change the default user agent for all client sessions in all threads created by the process.

The user agent string should use a format with the product name and version number separated by a slash. There can be multiple products listed in the user agent string separated by spaces, with additional optional information enclosed in parenthesis. For example, a valid user agent string for an application named "MyProgram" could look like this:

MyProgram/1.0 (Win32)

Some web services check the value of the user agent string to determine if a compatible client is being used to issue the request. The default value used by SocketTools is designed to emulate a common browser, but some services may require you change the user agent to use a specific value or include certain product names and versions.

To change the user agent string for a specific client session, use the SetHeader method to set a value for the User-Agent header. To get the current value of the default user agent string, use the GetDefaultUserAgent method.

To prevent any user agent string from being included with a request, include the HTTP_OPTION_NOUSERAGENT option when connecting to the server or use SetOption to enable that option after a connection has been established.

Using the HTTP_OPTION_NOUSERAGENT option to prevent sending a User-Agent header does not make requests anonymous. Servers may still identify clients based on IP address information, authentication credentials, request patterns or other HTTP headers included with the request.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtpv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also