简体   繁体   English

.NET中的代理身份验证 - 用于外部API

[英]Proxy Authentication in .NET - for external API

I'm developing a twitter messaging utility using Twitter API (twitterizer). 我正在使用Twitter API(twitterizer)开发一个Twitter消息传递实用程序。 But since I'm within a corporate proxy, I'm getting the error '407 Proxy Authentication Required'. 但由于我在公司代理中,我收到错误'407 Proxy Authentication Required'。 Is there any way to authenticate the user before calling the API or use the default proxy settings? 在调用API或使用默认代理设置之前,有没有办法验证用户?

PS Internally the API is using HttpWebRequest. PS内部API使用HttpWebRequest。

This does not answer your question. 这不能回答你的问题。 But the error you are getting is clearly a Proxy authentication error. 但是你得到的错误显然是代理身份验证错误。

You might want to either disable or enable the proxy. 您可能想要禁用或启用代理。

To disable the proxy, in the App.config file add the following configuration 要禁用代理,请在App.config文件中添加以下配置

<system.net>
  <defaultProxy enabled="false" useDefaultCredentials="false">
    <proxy/>
    <bypasslist/>
    <module/>
  </defaultProxy>
</system.net>

To enable the proxy and to use the default proxy settings(specified in IE) add this configuration in your App.config 要启用代理并使用默认代理设置(在IE中指定),请在App.config中添加此配置

<system.net>
  <defaultProxy enabled="true" useDefaultCredentials="true">
    <proxy/>
    <bypasslist/>
    <module/>
  </defaultProxy>
</system.net>

One of the possible programmatic solutions is to create following proxy: 可能的编程解决方案之一是创建以下代理:

IWebProxy proxy=HttpWebRequest.GetSystemWebProxy();  
proxy.Credentials = CredentialCache.DefaultCredentials;  

and then assign this to any object that make the network call and accept a proxy,eg: 然后将其分配给任何进行网络调用并接受代理的对象,例如:

WebClient client = new WebClient(); WebClient客户端=新WebClient();
client.proxy= proxy; client.proxy = proxy;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用具有基本身份验证的 .NET 获取外部 API,并使用 EF Core 将数据存储在 SQL 服务器数据库中 - Fetch external API using .NET with basic authentication and store data in SQL Server database using EF Core 成功进行外部提供程序身份验证后,向.net Web API响应中添加其他参数 - Add extra parameters to .net Web API response after successful external provider authentication 如何在ASP.NET MVC Web Api上使用外部身份验证服务 - How to use external authentication services on a ASP.NET MVC Web Api 从 Twitter API 获取用户的电子邮件以进行外部登录身份验证 ASP.NET MVC C# - Get user's email from Twitter API for External Login Authentication ASP.NET MVC C# 带有代理的 ASP .net 核心 jwt 身份验证 - ASP .net core jwt authentication with proxy API-HttpResponseMessage:需要(407)代理身份验证 - API - HttpResponseMessage: (407) proxy authentication required 在C#中使用Twilio语音api进行代理身份验证 - Proxy authentication with Twilio voice api in C# 调用外部API后WCF代理失败 - WCF Proxy fails following call to external API 如何使用.NET 4代理REST API - How to proxy a REST API with .NET 4 使用样板ASP.Net核心进行外部身份验证? - External Authentication with boilerplate ASP.Net core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM