Freigeben über


open Method (IXMLHTTPRequest)

 

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

JScript 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 XMLHTTP, this parameter is not case-sensitive. The verbs TRACE and TRACK are not allowed when IXMLHTTPRequest is hosted in the browser.

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 JScript example creates an XMLHTTP object, and then uses the open method to get a copy of books.xml at the IIS Web server running locally. The code then selects the <book id="bk101"> element to display as output.

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
xmlhttp.open("GET","https://localhost/books.xml", false);
xmlhttp.send();
var book = xmlhttp.responseXML.selectSingleNode("//book[@id='bk101']");
WScript.Echo(book.xml);

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 XMLHTTP, 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.

Return Values

S_OK
The value returned if successful.

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.

Note

Although this method accepts credentials passed via parameter, those credentials are not automatically sent to the server on the first request. The bstrUser and bstrPassword parameters are not sent to the server unless the server challenges the client for credentials with a 401 - Access Denied response.

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

See Also

abort Method (IXMLHTTPRequest)
onreadystatechange Property (IXMLHTTPRequest)
IXMLHTTPRequest