gpt4 book ai didi

c# - RestSharp 不支持 RestRequest 请求。凭据 - 无法通过 http 代理

转载 作者:行者123 更新时间:2023-11-30 14:23:51 31 4
gpt4 key购买 nike

使用下面的简单代码,RestClient 无法通过网络代理。它不尊重 request.Credentials 的值(value)

我能够访问我试图在浏览器中查询的站点;但是 RestClient 被我公司的代理阻止了。

try
{
RestClient client = new RestClient("http://services.groupkt.com/country/get/all");
RestRequest request = new RestRequest(Method.POST);

//set credentials to default
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

//also tried using client.UserAgent to spoof Firefox user-agent to no avail

request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");

IRestResponse response = client.Execute(request);
textBox1.Text = response.Content;
}
catch (Exception ex)
{
textBox1.Text = "ERROR:" + ex.Message;
}

所以我最终在 textBox1 中得到的是呈现为的 html:

Authorized Only

Secure Web Gateway has blocked your request because you have not beenauthorized and authorization is required.

URL:

User Name / Source: / 10.xx.xx.xx

Rule Set: Authentication with Kerberos and NTLM Fallback / Authenticate

With Kerberos (don't evaluate NTLM tokens)

IMPORTANT: when you access internet web pages you should comply with authorizations approvals according to [CompanyName] Internet Filtering.

generated 2017-05-05 15:04:08

RestSharp 104.1.0.0

换句话说,RestSharp 没有像预期的那样将默认凭据传输到 Web 代理。

最佳答案

我找到了答案:

        client.Proxy = new WebProxy(myProxyUrl);
client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

因此它不能像 HttpWebRequest 那样简单地从您的 Windows 设置中读取代理 url。您必须提供代理网址。

关于c# - RestSharp 不支持 RestRequest 请求。凭据 - 无法通过 http 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43813329/

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