我正在尝试将网页作为流返回。
当我尝试访问外部网址即“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")
答案 0 :(得分:0)
您收到401错误,因为网络服务器的身份验证拒绝了该请求。您可能需要明确设置凭据。
request.Credentials = New NetworkCredential("userName", "password", "domain")