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:
<% ' I want this page to be accessible for Cross Domain, especially from http://my.company.com (using JavaScript) Response.AddHeader "Access-Control-Allow-Origin", "http://my.company.com" 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 ' https://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx ' 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.