Export (0) Print
Expand All
1 out of 4 rated this helpful - Rate this topic

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(
  [in]                    const WCHAR *pwszMethod,
  [in]                    const WCHAR *pwszUrl,
  [in, optional]          IXMLHTTPRequest2Callback *pStatusCallback,
  [in, optional, unique]  const WCHAR *pwszUserName,
  [in, optional, unique]  const WCHAR *pwszPassword,
  [in, optional, unique]  const WCHAR *pwszProxyUserName,
  [in, optional, unique]  const WCHAR *pwszProxyPasssword
);

Parameters

pwszMethod [in]

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

pwszUrl [in]

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

pStatusCallback [in, optional]

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 [in, optional]

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 [in, optional]

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

pwszProxyUserName [in, optional]

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.

pwszProxyPasssword [in, optional]

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 | Windows Store apps]

Minimum supported server

Windows Server 2012 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Version

MSXML 6.0 and later

Header

Msxml6.h

IDL

Msxml6.idl

See also

Send Method
IXMLHTTPRequest2Callback Interface
IXMLHTTPRequest2

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.