CHttpClient::NormalizeUrl Method  
 
INT NormalizeUrl(
  LPCTSTR lpszUrl,  
  LPTSTR lpszNormalized,  
  INT nMaxLength  
);
INT NormalizeUrl(
  LPCTSTR lpszUrl,  
  CString& strNormalized  
);

The NormalizeUrl method normalizes the resource path and returns a canonical URL.

Parameters

lpszUrl
A null-terminated string which specifies an HTTP URL. This parameter cannot be NULL.
lpszNormalized
A null-terminated string buffer which will contain the normalized URL when the method returns. The buffer must be large enough to contain the entire URL including the terminating null character. If this parameter is NULL it will be ignored and the method will return the length of the normalized URL without copying any characters. An alternate version of this method accepts a reference to a CString object which will contain the normalized path when the method returns.
nMaxLength
An integer value which specifies the maximum number of characters which can be copied into the string buffer. If this value is zero, the lpszNormalized parameter is ignored and the method will return the length of the normalized URL without copying any characters.

Return Value

This method returns the number of characters copied into the string buffer, not including the terminating null character. If the lpszNormalized parameter is NULL, it will return the length of the normalized URL but will not copy any characters. If the method fails, it will return HTTP_ERROR. To get extended error information, call GetLastError.

Remarks

This method will accept a standard HTTP or HTTPS URL and return a canonical version of that URL. Normalization will remove extraneous path delimiters and collapse the path if there are references to parent directories. If non-standard port numbers are included in the URL, they will be preserved. For example, if the following URL is provided to the method:

https://www.example.com:443/file/..//project/filename.pdf

It will return the following as the normalized URL:

https://www.example.com/project/filename.pdf

Because the port number specified in the original URL is the default port number for secure HTTP connections, it is removed. In addition, the path is collapsed and the extraneous path delimiters are removed.

This method is primarily intended to normalize URLs which may be entered by a user or read from a configuration file. It is not necessary to call this method prior to calling ConnectUrl because it will always be normalized internally prior to the connection being established. If you wish to check a URL to ensure it is valid and the server name can be resolved to an IP address, use the ValidateUrl method.

If you need to normalize a remote file path, use the NormalizePath method.

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