open Method (IXMLHTTPRequest)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

open Method (IXMLHTTPRequest)

Initializes an MSXML2.XMLHTTP request and specifies the method, URL, and authentication information for the request.

[Script]

Script Syntax

oXMLHttpRequest.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);

Parameters

bstrMethod
The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND. For IXMLHTTPRequest, this parameter is not case-sensitive.
bstrUrl
The requested URL. This can be either an absolute URL, such as "http://Myserver/Mypath/Myfile.asp", or a relative URL, such as "../MyPath/MyFile.asp".
varAsync [optional]
A Boolean indicator of whether the call is asynchronous. The default is True (the call returns immediately). If set to True, attach an onreadystatechange property callback so that you can tell when the send call has completed.
bstrUser [optional]
The name of the user for authentication. If this parameter is Null ("") or missing and the site requires authentication, the component displays a logon window.
bstrPassword [optional]
The password for authentication. This parameter is ignored if the user parameter is Null ("") or missing.

Example

The following script example creates an XMLHTTP object, and then uses the open method to synchronously open an Active Server Pages (ASP) page. The script then posts an XML document to an ASP page, which uses the load method to load the document.

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.5.0");
xmlHTTP.open("GET","http://myserver/save.asp", false);
xmlHTTP.send(xmlDoc)

The following code belongs on the server.

<% xmlDoc.load(Request); %>
[Visual Basic]

Visual Basic Syntax

oXMLHttpRequest.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword)

Parameters

bstrMethod
The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND. For IXMLHTTPRequest, this parameter is not case-sensitive.
bstrUrl
The requested URL. This can be either an absolute URL, such as "http://Myserver/Mypath/Myfile.asp", or a relative URL, such as "../MyPath/MyFile.asp".
varAsync [optional]
A Boolean indicator of whether the call is asynchronous. The default is True (the call returns immediately). If set to True, attach an onreadystatechange property callback so that you can tell when the send call has completed.
bstrUser [optional]
The name of the user for authentication. If this parameter is Null ("") or missing and the site requires authentication, the component displays a logon window.
bstrPassword [optional]
The password for authentication. This parameter is ignored if the user parameter is Null ("") or missing.
[C/C++]

C/C++ Syntax

HRESULT open(BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync,
 VARIANT bstrUser, VARIANT bstrPassword);

Parameters

bstrMethod [in]
The HTTP method used to open the connection, such as PUT or PROPFIND. For IXMLHTTPRequest, this parameter is not case-sensitive.
bstrUrl [in]
The requested URL. This can be either an absolute URL, such as "http://Myserver/Mypath/Myfile.asp", or a relative URL, such as "../MyPath/MyFile.asp".
varAsync [in, optional]
A Boolean indicator as to whether the call is asynchronous. The default is True (the call returns immediately). If set to True, attach an onreadystatechange property callback so that you can tell when the send call has completed.
bstrUser [in, optional]
The name of the user for authentication. If this parameter is Null ("") or missing and the site requires authentication, the component displays a logon window.
bstrPassword [in, optional]
The password for authentication. This parameter is ignored if the user parameter is Null or missing.

C/C++ Return Values

S_OK
The value returned if successful.

C/C++ Example

HRESULT hr;
IXMLHttpRequest *pIXMLHttpRequest = NULL;

try
{
   // Create XMLHttpRequest object and initialize pIXMLHttpRequest.
   hr = pIXMLHttpRequest->open(_bstr_t(_T("PUT")),
      _bstr_t(_T("GET","http://MyServer/Sample.xml", false)),
      _variant_t(VARIANT_FALSE), _variant_t(""), _variant_t(""));
   if(SUCCEEDED(hr))
      ::MessageBox(NULL, _T("Success !"), _T(""), MB_OK);
}
catch(...)
{
   DisplayErrorToUser();
}
// Release pIXMLHttpRequest when finished with it.

Remarks

After calling this method, you must call send to send the request and data, if any, to the server.

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

abort Method | onreadystatechange Property

Applies to: IXMLHTTPRequest