简体   繁体   English

从经典ASP页面调用PHP + CURL函数

[英]Call a PHP+CURL function from a Classic ASP page

I have a php + curl function that captures the "HTTP 301" responses. 我有一个php + curl函数,可捕获“ HTTP 301”响应。 The page is named get_header.php and is located in the folder /exe: 该页面名为get_header.php,位于文件夹/ exe中:

function getheader($url)
// Use curl to fetch the HTTP Headers
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1); // just the header
curl_setopt($ch, CURLOPT_NOBODY, 1); // not the body
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
preg_match('/Location: (.*)\n/', $output, $matches);
// if no redirect header then return the original url
return isset($matches[1]) ? $matches[1] : $url;
}
echo(getheader($_GET['url']));

However, I need to use this script in a classic asp page. 但是,我需要在经典的ASP页面中使用此脚本。 I tried to call it via HTTP: 我试图通过HTTP调用它:

Dim x: Set x = CreateObject("MSXML2.ServerXMLHTTP")     
Dim y: y = "http://mysite.com/exe/get_header.php?url=" & url
x.Open "GET", y, false 
x.Send()
Dim z: z = x.ResponseText

Although it works, this is not the ideal solution since both pages are on the same domain. 尽管它可以工作,但这不是理想的解决方案,因为两个页面都在同一个域中。 In fact it has generated slowness of requests. 实际上,它已导致请求缓慢。 So how could I solve this problem? 那么我该如何解决这个问题呢? The ideal solution would be a vbscript or javascript version of my PHP function. 理想的解决方案是我的PHP函数的vbscript或javascript版本。 Thanks! 谢谢!

Here's the solution: 解决方法如下:

Dim x: Set x = CreateObject("WinHttp.WinHttpRequest.5.1")
x.Option(6) = False
x.Open "GET", url, false
x.Send()
If x.status = 301 Then
Dim z: z = x.getResponseHeader("Location")
End If

Thanks to FAngel for your replies! 感谢FAngel的回复!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM