Share via


setProxyCredentials Method (ServerXMLHTTP-IServerXMLHTTPRequest)

 

Specify proxy authentication credentials.

JScript Syntax

oSrvXMLHTTPRequest.setProxyCredentials(username, password);  

Parameters

username
The name of the user to be authenticated.

password
The password for the user to be authenticated.

Example

The following example shows how to set proxy credentials.

var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");  
var sURL = "https://www.adventure-works.com";  
  
try {  
    xmlhttp.setProxy("2", "adventure-works", "<local>");      
    xmlhttp.open("GET", sURL , false);  
    xmlhttp.setProxyCredentials("adventure-works2\\proxyuser", "password1");  
  
    xmlhttp.send();  
    WScript.Echo("No exception, and ServerXMLHTTP.status is " + xmlhttp.status);  
}  
catch (e) {  
    WScript.Echo("Exception caught. There should be an exception if the credentials are wrong.");  
    WScript.Echo(e.number + " " + e.description);  
    if (xmlhttp.status != 407) {  
        WScript.Echo("It should have returned 407 (not authorized), but returned = " + xmlhttp.status);  
    } else {  
        WScript.Echo("With wrong credentials, status returned 407 as expected");  
    }  
}  

C/C++ Syntax

HRESULT setProxyCredentials(  
    BSTR bstrUserName,  
    BSTR bstrPassword);  

Parameters

bstrUserName[in]
The name of the user to be authenticated.

bstrPassword[in]
The password for the user to be authenticated.

Return Values

S_OK
Value returned if successful.

E_FAIL
Value returned if name or value is invalid.

Versioning

Implemented in: MSXML 6.0 and later

See Also

setProxy Method (ServerXMLHTTP-IServerXMLHTTPRequest)
IServerXMLHTTPRequest-ServerXMLHTTP Members