使用VBNet进行HttpWebRequest [英] HttpWebRequest with VBNet
本文介绍了使用VBNet进行HttpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用VbNet从我们公司的网站上下载报告。我有以下代码:
I am trying to download a report off of our company website using VbNet. I have the following code:
Dim hwrequest As Net.HttpWebRequest = Net.HttpWebRequest.Create("https://delph.am.mycompany.com/apps/Reports/ExportDocument11.asp?ID=826&Request=List&OpenType=Edit")
hwrequest.CookieContainer = cookies
hwrequest.Accept = "*/*"
hwrequest.AllowAutoRedirect = False
hwrequest.UserAgent = "http_requester/0.1"
hwrequest.Timeout = 60000
hwrequest.Method = "GET"
Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
Dim responseStream As IO.StreamReader = _
New IO.StreamReader(hwresponse.GetResponseStream())
responseData = responseStream.ReadToEnd()
End If
但是Response对象只返回
But the Response object just returns
<head><title>Object moved</title></head>
<body><h1>Object Moved</h1>This object may be found <a HREF="/Security/ErrorTrap.asp?
ErrorID=7">here</a>.</body>
和响应的Location标头返回:{X = 46,Y = 46}和我我不确定这意味着什么。
有谁能告诉我我做错了什么?在此先感谢。
and the Location header of the response returns: {X=46,Y=46} and I am not sure what that means.
Can anyone please tell me what I am doing wrong? Thanks in advance.
推荐答案
HttpWebRequest类不会像浏览器那样遵循重定向。您必须获取报告文件的实际URL,而不是您正在使用的URL。您正在检索的是一个重定向到另一个页面的HTML页面。
The HttpWebRequest class will not follow redirects like a browser will. You have to get the actual URL of the report file, not the one you're using. What you're retrieving is a HTML page that redirects to another page.
这篇关于使用VBNet进行HttpWebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文