Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何停止WebRequest使用上次成功的凭据-重置凭据缓存_Vb.net_Visual Studio 2015_Webrequest_.net 4.5.2 - Fatal编程技术网

Vb.net 如何停止WebRequest使用上次成功的凭据-重置凭据缓存

Vb.net 如何停止WebRequest使用上次成功的凭据-重置凭据缓存,vb.net,visual-studio-2015,webrequest,.net-4.5.2,Vb.net,Visual Studio 2015,Webrequest,.net 4.5.2,当使用以下代码时,如果我指定了错误的用户名/密码组合,则会出现407错误 如果我使用了正确的页面,我会得到请求的页面 如果我用错误的用户名/密码重试,我会得到正常的响应 出于某种原因,WebRequest会为请求的URL缓存代理的用户名/密码(CredentialCache)组合。如果我更改指向不同域的URL,我会得到一个正确的407 如何阻止WebRequest使用上次成功的凭据 Dim request As WebRequest = WebRequest.Create("http:/

当使用以下代码时,如果我指定了错误的用户名/密码组合,则会出现407错误

如果我使用了正确的页面,我会得到请求的页面

如果我用错误的用户名/密码重试,我会得到正常的响应

出于某种原因,WebRequest会为请求的URL缓存代理的用户名/密码(CredentialCache)组合。如果我更改指向不同域的URL,我会得到一个正确的407

如何阻止WebRequest使用上次成功的凭据

    Dim request As WebRequest = WebRequest.Create("http://contoso.com")

    request.Proxy = New WebProxy("http://myproxy:8080")
    Dim username = InputBox("Username")
    Dim password = InputBox("Password")
    request.Proxy.Credentials = New NetworkCredential(username, password)

    Try
        Using response = request.GetResponse()
            ' Display the status.
            txt_response.Text = CType(response, HttpWebResponse).StatusDescription & "Response is from cache?: " & response.IsFromCache
            ' Get the stream containing content returned by the server.
            Dim dataStream As Stream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            txt_Result.Text = responseFromServer
            ' Clean up the streams and the response.
            reader.Close()
            response.Close()
        End Using
    Catch ex As WebException
        txt_response.Text = ex.Status & ": " & ex.Message
    End Try