GetDefaultUserAgent Method  
 
INT GetDefaultUserAgent(
  LPTSTR lpszUserAgent,  
  INT nMaxLength  
);
INT GetDefaultUserAgent(
  CString& strUserAgent  
);

The GetDefaultUserAgent method returns the default user agent string which is included with all requests.

Parameters

lpszUserAgent
A buffer which will contain the default user agent string when the method returns. The buffer must be large enough to contain the entire user agent string including the terminating null character. This parameter cannot be NULL. An alternate form of the method accepts a CString variable which will contain the user agent.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the buffer.

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

When you submit a request to the server, a header named User-Agent is automatically defined which identifies your application. It typically uses a format where you have a product name and version number separated by a slash. There can be multiple products listed in the user agent string, with additional optional information enclosed in parenthesis.

A server uses the user agent to determine what type of client has issued the request, including what operating system and browser version was used. The HttpGetDefaultUserAgent method returns a copy of that default value. The value of the user agent string depends on which version of Windows the client is running on and whether the process is 32-bit or 64-bit. For example, a 64-bit application will typically return a value like this:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/134.0.0.0 Safari/537.36 SocketTools/12.0

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 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.

You can change the value of the user agent string in one of two ways. You can use the SetHeader method to set the User-Agent header to a specific value for a client session, or you can use SetDefaultUserAgent to set the default user agent string for all requests. If you use SetHeader to change the user agent string for a client session, it will always override the default value.

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