Link to home
Start Free TrialLog in
Avatar of JClayton7
JClayton7

asked on

Download File with ServerXMLHTTP with setProxyCredentials

I am trying to run a VBScrpit to download a file daily from a website. In order to do this I need to set the proxy credentials. THe scrpit below works inside the network, and I have verified that the two URLs are accurate (if put in IE both go where I want) but after I enter my proxy credentials and do a .send the object status returns HTTP Error 407 (proxy authorization required) I know that the credentials I have are what I enter manually, although I reliase that it may not be the full username. Also I cant bypass the proxy because the website verifies the IP address before allowing me to login.  Any suggestions?  
Dim sFileURL, objXMLHTTP, objADOStream, objFSO, sLocation,  username, password,url
     
 username = "my username"
 password = "my password"
 sFileURL = "Login URL"
 sLocation = "Path" 
 url = "File URL"
 
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")

 objXMLHTTP.setProxy 2, "my proxy"   
 objXMLHTTP.Open "GET", sFileURL, False 
 objXMLHTTP.setProxyCredentials username, password
 objXMLHTTP.send()
 
If objXMLHTTP.Status <> 200 Then    
	msgbox objXMLHTTP.status 
End if 
 
objXMLHTTP.Open "GET", url, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
 
        Set objADOStream = CreateObject("ADODB.Stream")
        objADOStream.Open
 
        objADOStream.Type = 1
        objADOStream.Write objXMLHTTP.ResponseBody
 
        objADOStream.Position = 0
 
        Set objFSO = CreateObject
                     ("Scripting.FileSystemObject")
 
         If objFSO.FileExists(sLocation) Then 
                      objFSO.DeleteFile sLocation
 
        
         Set objFSO = Nothing
 
        
         objADOStream.SaveToFile sLocation
 
         objADOStream.Close
  
         Set objADOStream = Nothing
 
End If
 
Set objXMLHTTP = Nothing

Open in new window

Avatar of JClayton7
JClayton7

ASKER

I got it to work, It was a username issue. But the file i am trying to download is a .gz and all I seem to be getting is the XML not the actual file. Any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of judgeking
judgeking
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Clayton, any update?