It’s very frustrating to have to work with ASP again, after so many years…
I wanted to use an ASP page to get a remote page. However I needed to pass some NTLM authenticate to it.
After a few searches I found this solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <% ' I want this page to be accessible for Cross Domain, especially from http://my.company.com (using JavaScript) Response.AddHeader "Access-Control-Allow-Credentials" , "true" ' get "url" from the parameters set REMOTE_FILE_URL=Request.QueryString( "url" ) If REMOTE_FILE_URL <> "" Then ' You could use MSXML2.ServerXMLHTTP but you would have to hardcoded the login/password ' Example: ' Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") ' http.open "GET", REMOTE_FILE_URL, False, "domain\user_name", "Password" ' So here we'll use "WinHttp.WinHttpRequest.5.1" that will pass the IIS' credentials set http = CreateObject( "WinHttp.WinHttpRequest.5.1" ) http.SetAutoLogonPolicy 0 ' we can define timeouts (http://msdn.microsoft.com/en-us/library/windows/desktop/aa384061(v=vs.85).aspx) ' http.SetTimeouts(resolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout) ' example: http.SetTimeouts 60000, 60000, 60000, 60000 ' we can add some headers to the request that will be done by the server ' http.SetRequestHeader "Content-type", "application/json" ' multiple options can be defined ' examples: ' to define the user agent: http.Option(0) = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)" ' to ignore ssl errors: http.Option(4) = 13056 ' if you use a proxy http.SetProxy 2, "proxy:80" ' method: open(http method, absolute uri to request, async (true: async, false: sync) http.open "GET" , REMOTE_FILE_URL, False http.send 'Response.AddHeader http.GetAllResponseHeaders Response.write http.responseText Else Response.write "Parameter 'url' not provided." End If %> |
Here I use the URL parameter url
to call that specific page.