1

我正在尝试在 ASP 中制作 LINK FINDER 应用程序
它的工作分为 5 个步骤

  1. 向 www.foo.com 的服务器发送 http 请求
  2. 检查请求状态
  3. 如果是 200 则转到第 4 步,否则显示错误
  4. 解析所有链接
  5. Send http request to server to parsed link

我能够完成前 4 步,但在第 5 步面临挑战

我得到 3 种类型的链接

1.)绝对链接:http
://www.foo.com/file.asp 2.)从根目录链接,需要域名 例如/folder2/file2.asp
3.)相对链接:../file3.asp

挑战

当我请求www.foo.com时,它是301 重定向www.foo.com/folder3/folder3/file3.asp

我正在获取重定向页面的 html 内容,但没有得到重定向的 url 并且无法检查第三种类型的链接

使用以下代码

Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "GET", "http://www.foo.com"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXmlHttp.send PostData
If ServerXmlHttp.status = 200 Then
 //My CODE

希望快速响应......或任何其他关于asp,vb.net中的链接查找器的想法

4

1 回答 1

3

它超出了 ServerXMLHTTP 功能。
相反,您必须使用IWinHttpRequest或其他能够管理重定向的第三方组件。
在以下示例中,req.Option(WHR_URL)即使重定向也返回当前 url。
默认情况下,选项req.option(WHR_EnableRedirects)类似于TrueServerXMLHTTP。
因此,我添加了一条注释掉的行,显示如何禁用重定向。

Const WHR_URL = 1
Const WHR_EnableRedirects = 6
'Enum constants are listed at http://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx
Dim req
Set req = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
    'req.Option(WHR_EnableRedirects) = False 'don't follow the redirects
    req.open "GET", "http://www.foo.com", False
    req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    req.send PostData
If req.Status = 200 Then
    Response.Write "Last URL : " & req.Option(WHR_URL)
End If
于 2013-12-03T23:02:41.787 回答