GetResponse 不适用于内部 url

GetResponse not working for internal url

我正在尝试 return 将网页作为流。

当我尝试访问外部 url 即“http://www.google.com'. But when i try and access a website on our server i.e. '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")

您收到 401 错误是因为网络服务器的身份验证拒绝了请求。您可能需要明确设置您的凭据。

            request.Credentials = New NetworkCredential("userName", "password", "domain")