IXMLHTTPRequest2::Open method (msxml6.h)
Initializes an IXMLHTTPRequest2 request and specifies the method, URL, and authentication information for the request. After calling this method, you must call the Send method to send the request and data, if any, to the server.
HRESULT Open(
[in] const WCHAR *pwszMethod,
[in] const WCHAR *pwszUrl,
[in, optional] IXMLHTTPRequest2Callback *pStatusCallback,
[in, optional] const WCHAR *pwszUserName,
[in, optional] const WCHAR *pwszPassword,
[in, optional] const WCHAR *pwszProxyUserName,
[in, optional] const WCHAR *pwszProxyPassword
);
[in] pwszMethod
The HTTP method used to open the connection, such as GET or POST. For XMLHTTP, this parameter is not case-sensitive.
[in] pwszUrl
The requested URL. This must be an absolute URL, such as "http://Myserver/Mypath/Myfile.asp".
[in, optional] pStatusCallback
A callback interface implemented by the app that is to receive callback events.
When the Send Method is successful, the methods on this interface are called to process the response or other events.
[in, optional] pwszUserName
The name of the user for authentication. If this parameter is a Null and the site requires authentication, credentials will be managed by Windows, including displaying a logon UI, unless disabled by SetProperty.
[in, optional] pwszPassword
The password for authentication. This parameter is ignored if the pwszUserName parameter is Null or missing.
[in, optional] pwszProxyUserName
The name of the user for authentication on the proxy server. If this parameter is a Null or empty string and the site requires authentication, credentials will be managed by Windows, including displaying a logon UI, unless disabled by SetProperty.
[in, optional] pwszProxyPassword
The password for authentication on the proxy server. This parameter is ignored if the pwszProxyUserName parameter is Null or missing.
Returns S_OK on success.
Although this method accepts credentials passed via parameter, these credentials are not automatically sent to the server on the first request. The pwszUserName and pwszPassword parameters are not sent to the server unless the server challenges the client for credentials with a 401 - Unauthorized response.
//
// Create and initialize an IXMLHTTPRequest2 object
//
hr = CoCreateInstance(CLSID_FreeThreadedXMLHTTP60,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&spXHR));
//
//Create and initialize an IXMLHTTPRequest2Callback object
//
hr = MakeAndInitialize<CXMLHttpRequest2Callback>(&spXhrCallback);
hr = spXHR->Open(L"GET", // Method.
pcwszUrl, // Url.
spXhrCallback.Get(), // Callback.
NULL, // Username.
NULL, // Password.
NULL, // Proxy username.
NULL); // Proxy password.
//
//Send the GET request
//
hr = spXHR->Send(NULL, 0);
hr = spXhrCallback->WaitForComplete(&dwStatus);
For the complete examples, see the XML HTTP Request 2 GET sample and XML HTTP Request 2 POST sample.
Requirement | Value |
---|---|
Minimum supported client | Windows 8 [desktop apps | UWP apps],MSXML 6.0 and later |
Minimum supported server | Windows Server 2012 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | msxml6.h |