{"id":1841,"date":"2017-08-07T18:23:02","date_gmt":"2017-08-07T16:23:02","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=1841"},"modified":"2017-11-16T20:36:13","modified_gmt":"2017-11-16T19:36:13","slug":"classic-asp-to-get-a-remote-page-with-ntlm-authenticate","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2017\/08\/07\/classic-asp-to-get-a-remote-page-with-ntlm-authenticate\/","title":{"rendered":"Classic ASP to get a remote page with NTLM authenticate"},"content":{"rendered":"<p>It&#8217;s very frustrating to have to work with ASP again, after so many years&#8230;<\/p>\n<p>I wanted to use an ASP page to get a remote page. However I needed to pass some NTLM authenticate to it.<\/p>\n<p>After a few searches I found this solution:<\/p>\n<pre class=\"brush:vb\">\r\n&lt;%\r\n' I want this page to be accessible for Cross Domain, especially from http:\/\/my.company.com (using JavaScript)\r\nResponse.AddHeader \"Access-Control-Allow-Origin\", \"http:\/\/my.company.com\"\r\nResponse.AddHeader \"Access-Control-Allow-Credentials\", \"true\"\r\n\r\n' get \"url\" from the parameters\r\nset REMOTE_FILE_URL=Request.QueryString(\"url\")\r\n\r\nIf REMOTE_FILE_URL &lt;> \"\" Then\r\n  ' You could use MSXML2.ServerXMLHTTP but you would have to hardcoded the login\/password\r\n  ' Example:\r\n  '    Set http = Server.CreateObject(\"MSXML2.ServerXMLHTTP.6.0\")\r\n  '    http.open \"GET\", REMOTE_FILE_URL, False, \"domain\\user_name\", \"Password\"\r\n  ' So here we'll use \"WinHttp.WinHttpRequest.5.1\" that will pass the IIS' credentials\r\n  set http = CreateObject(\"WinHttp.WinHttpRequest.5.1\")\r\n  http.SetAutoLogonPolicy 0\r\n\r\n  ' we can define timeouts (http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa384061(v=vs.85).aspx)\r\n  ' http.SetTimeouts(resolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout)\r\n  ' example: http.SetTimeouts 60000, 60000, 60000, 60000\r\n\r\n  ' we can add some headers to the request that will be done by the server\r\n  ' http.SetRequestHeader \"Content-type\", \"application\/json\"\r\n\r\n  ' multiple options can be defined\r\n  ' https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa384108(v=vs.85).aspx\r\n  ' examples:\r\n  ' to define the user agent: http.Option(0) = \"Mozilla\/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident\/6.0)\"\r\n  ' to ignore ssl errors: http.Option(4) = 13056\r\n\r\n  ' if you use a proxy\r\n  http.SetProxy 2, \"proxy:80\"\r\n\r\n  ' method: open(http method, absolute uri to request, async (true: async, false: sync)\r\n  http.open \"GET\", REMOTE_FILE_URL, False\r\n  http.send\r\n\r\n  'Response.AddHeader http.GetAllResponseHeaders\r\n  Response.write http.responseText\r\nElse\r\n  Response.write \"Parameter 'url' not provided.\"\r\nEnd If\r\n%>\r\n<\/pre>\n<p>Here I use the URL parameter <code>url<\/code> to call that specific page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s very frustrating to have to work with ASP again, after so many years&#8230; 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: &lt;% &#8216; I want this page to be accessible for Cross [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[170,13,33],"tags":[123,152,158],"class_list":["post-1841","post","type-post","status-publish","format-standard","hentry","category-english","category-niveau-intermediaire","category-programmation","tag-english","tag-niveau-intermediaire","tag-programmation"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1841"}],"version-history":[{"count":7,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1841\/revisions"}],"predecessor-version":[{"id":1860,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1841\/revisions\/1860"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}