IXMLHTTPRequest2::Open method

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.

Syntax

HRESULT Open(
  const WCHAR              *pwszMethod,
  const WCHAR              *pwszUrl,
  IXMLHTTPRequest2Callback *pStatusCallback,
  const WCHAR              *pwszUserName,
  const WCHAR              *pwszPassword,
  const WCHAR              *pwszProxyUserName,
  const WCHAR              *pwszProxyPassword
);

Parameters

pwszMethod

The HTTP method used to open the connection, such as GET or POST. For XMLHTTP, this parameter is not case-sensitive.

pwszUrl

The requested URL. This must be an absolute URL, such as "http://Myserver/Mypath/Myfile.asp".

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.

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.

pwszPassword

The password for authentication. This parameter is ignored if the pwszUserName parameter is Null or missing.

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.

pwszProxyPassword

The password for authentication on the proxy server. This parameter is ignored if the pwszProxyUserName parameter is Null or missing.

Return value

Returns S_OK on success.

Remarks

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.

Examples

//
// 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 download the XML HTTP Request 2 GET sample and XML HTTP Request 2 POST sample from the Windows Sample Gallery.

Requirements

   
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

See also

IXMLHTTPRequest2

IXMLHTTPRequest2Callback Interface

Send Method