|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Proxy Auth. in this VB script
I'm on the hunt for a little help here. I have written this piece of VB script to scrap a graphic from a web page and save it to my local server.
However, this script was written with a fair bit of help from my friends - and i'm not much of a programmer. This script has to run on a corporate network which all web traffic goes out via our proxy which requires authentication. Does anyone know of a method where I can get this script to pipe all it's request out via a proxy, and if it is possible to specify authentication details for the proxy server. All and any help greatly appreciated. Michael ==== Dim Inet, strHTML, Pos1, Pos2 strHTML = getHttpFile("http://www.unitedmedia.com/comics/dilbert/archive/") strHTML = GetDilbert(strHTML) BinarySaveURL strHTML, "dir\filename.ext" Function GetDilbert(strHTML) strHTML = getHttpFile("http://www.unitedmedia.com/comics/dilbert/archive/") Pos1 = InStr(strHTML, "/comics/dilbert/archive/images/dilbert") If pos1=0 then Response.Write("Sorry, page did not load...ReTrying") Response.Redirect("DailyDilbert.asp") Else Pos2 = InStr(pos1,strhtml, ".gif") strHTML = Mid(strHTML, Pos1, (Pos2+4 )- Pos1) strHTML="http://www.unitedmedia.com" & strhtml End If GetDilbert =strHTML End Function Function GetHTTPFile(File) Dim DLText Set DLText = CreateObject("WinHttp.WinHttpRequest.5.1") DLText.Open "GET", File, True DLText.Send If DLText.WaitForResponse(5) = True Then GetHTTPFile = BinToStr(DLText.ResponseBody) End If end function Function BinToStr(Binary) Dim I Dim StrOut For I = 1 To LenB(Binary) StrOut = StrOut & Chr(AscB(MidB(Binary, I, 1))) Next BinToStr = StrOut End Function Sub BinarySaveURL(URL, fn) 'Create an Http object, use any of the four objects Dim Http Set Http = CreateObject("WinHttp.WinHttpRequest.5.1") 'Send request To URL Http.Open "GET", URL, False Http.Send 'Get response data As a string ss = Http.ResponseBody Dim FS: Set FS = CreateObject("Scripting.FileSystemObject") 'Create text stream object Dim TextStream Set TextStream = FS.CreateTextFile(fn) 'Convert binary data To text And write them To the file TextStream.Write BinToStr(ss) End Sub ====== |
|
#2
|
|||
|
|||
|
Did you ever get a solution for authenticating to the proxy server? I am having a similar issue.
|
|
#3
|
|||
|
|||
|
Nope, still hunting for a solution.
|
|
#4
|
|||
|
|||
|
Assuming that you still did not get an answer.
The trick is very easy. Replace Http.Open "GET", URL, False with Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1 Const HTTPREQUEST_PROXYSETTING_PROXY = 2 Const AutoLogonPolicy_Always = 0 Http.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, "yourproxy:80", "*.intra" Http.Open "GET", URL, False 'Http.SetCredentials "Domain\Account","*********",HTTPREQUEST_SETCREDENTIALS_FOR_PROXY Http.SetAutoLogonPolicy AutoLogonPolicy_Always either use setautologon to use current user for authentication, or setcredentials to specify a user and password Hope this helps |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Proxy Auth. in this VB script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|