我正在尝试将网页作为流返回。
当我尝试访问外部 url 即“ http://www.google.com ”时,我到目前为止所得到的东西是有效的。但是当我尝试访问我们服务器上的网站时,即“ http://servername/applicationname/default.aspx ”。
以下是我目前拥有的代码,适用于外部:
Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.google.com/search?q=google"), HttpWebRequest)
Dim response As HttpWebResponse = CType(request.GetResponse, HttpWebResponse)
Dim resStream As Stream = response.GetResponseStream
但是当我用这条线尝试时,我得到了The remote server returned an error: (401) Unauthorized.
Dim request As HttpWebRequest = CType(WebRequest.Create("http://Server/Application/SubFolder/testing.aspx"), HttpWebRequest)
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
我尝试使用以下方法更改它访问服务器的凭据:
request.Credentials = CredentialCache.DefaultCredentials
我尝试过使用网络客户端:
Dim myWebClient As New WebClient()
Dim myStream As Stream = myWebClient.OpenRead("http://Server/Application/SubFolder/testing.aspx")