gpt4 book ai didi

c# - 代理验证错误

转载 作者:行者123 更新时间:2023-11-30 17:15:05 30 4
gpt4 key购买 nike

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.example.com");
NetworkCredential nc = new NetworkCredential("myname", "mypass");
WebProxy myproxy = new WebProxy("192.168.1.1:8080", false);
myHttpWebRequest.Proxy = myproxy;
myHttpWebRequest.Proxy = WebRequest.DefaultWebProxy;
myHttpWebRequest.Method = "GET";

HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
MessageBox.Show("Ok");

我正在使用此代码连接网站(C#.net 桌面应用程序)。但我收到此错误消息:

The remote server returned an error: (407) Proxy Authentication Required.

我该如何解决这个问题?

最佳答案

您当前未在代理中使用凭据。这是一个 example adapted from MSDN of how to use your NetworkCredential :

class Downloader
{
static void Main(string[] args)
{
NetworkCredential nc = new NetworkCredential(args[0], args[1]);
WebProxy proxy = new WebProxy(args[2], false);
proxy.Credentials = nc;

WebRequest request = new WebRequest(args[3]);
request.Proxy = proxy;
using (WebResponse response = request.GetResponse())
{
Console.WriteLine(
@"{0} - {1} bytes",
response.ContentType,
response.ContentLength);
}
}
}

当我编译并运行这个完整的例子时:

C:\cs>csc proxy.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.


C:\cs>proxy user pass http://proxy:80 http://www.google.com
text/html; charset=ISO-8859-1 - 31398 bytes

C:\cs>

当然,我为我的工作帐户使用了我的实际用户/通行证和代理。

关于c# - 代理验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8223396/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com