ServerXMLHTTP的要求returing数据,但后301重定向没有返回最终页面的网址 [英] ServerXMLHTTP request returing data but not returning url of final page after 301 redirection
问题描述
我试图让LINK FINDER应用在ASP结果
的它的工作分为5个步骤的
- 在www.foo.com发送HTTP请求到服务器
- 检查请求的状态
- 如果其200然后移动到第4步,否则显示错误
- 解析所有链接
- 的
发送HTTP请求到服务器来解析链接
的
我可以先做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,而不是能够检查第三类型的链接的
使用以下code
设置的ServerXMLHTTP =的Server.CreateObject(MSXML2.ServerXMLHTTP.6.0)
ServerXmlHttp.openGET,http://www.foo.com
ServerXmlHttp.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
ServerXmlHttp.send的PostData
如果ServerXmlHttp.status = 200然后
//我的code
块引用>对于希望快速反应...
或者在ASP链接发现者任何其他的想法,vb.net解决方案这是出了ServerXMLHTTP的能力。
相反,你必须使用 IWinHtt prequest 或其他第三方组件,它能够管理重定向。
在下面的例子中,req.Option(WHR_URL)
返回即使重定向的URL。
选项req.option(WHR_EnableRedirects)
是真
默认情况下,像ServerXMLHTTP的。
所以,我添加注释掉展示如何禁用重定向行。常量WHR_URL = 1
常量WHR_EnableRedirects = 6
枚举常数在http://msdn.microsoft.com/en-us/library/windows/desktop/aa384108(v=vs.85).aspx上市
昏暗的REQ
设置REQ =的Server.CreateObject(WinHttp.WinHtt prequest.5.1)
req.Option(WHR_EnableRedirects)= FALSE不遵循重定向
req.openGET,http://www.foo.com,假
req.setRequestHeader内容类型,应用程序/ x-WWW的形式urlen codeD
req.send的PostData
如果req.Status = 200然后
RESPONSE.WRITE最后的URL:&放大器; req.Option(WHR_URL)
万一I am trying to make LINK FINDER app in ASP
It working is divided into 5 step
- Send http request to server at www.foo.com
- Check status of request
- If its 200 then move to step 4 otherwise show error
- Parse all link
Send http request to server to parsed link
I am able to do first 4 step, But facing challenge in 5th step
I am getting 3 type of links
1.)absolute link : http://www.foo.com/file.asp
2.)links from root directory, which need domain name eg /folder2/file2.asp
3.)relative link : ../file3.aspChallenge
When I am requesting www.foo.com , which is 301 redirected to www.foo.com/folder3/folder3/file3.asp
I am getting html content of redirected page, But don't get redirected url and not able to check 3rd type of links
Using following code
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
Hope for quick response... or any other idea for link finder in asp , vb.net
解决方案It's out of the ServerXMLHTTP capabilities.
Instead you have to use IWinHttpRequest or another third-party component that able to manage redirects.
In the following example,req.Option(WHR_URL)
returns the current url even if redirected.
Optionreq.option(WHR_EnableRedirects)
isTrue
by default like ServerXMLHTTP.
So, I've added a line commented out showing how to disable redirects.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
这篇关于ServerXMLHTTP的要求returing数据,但后301重定向没有返回最终页面的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!