Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy Authentication in .NET - for external API

I'm developing a twitter messaging utility using Twitter API (twitterizer). But since I'm within a corporate proxy, I'm getting the error '407 Proxy Authentication Required'. Is there any way to authenticate the user before calling the API or use the default proxy settings?

P.S Internally the API is using HttpWebRequest.

like image 400
softwarematter Avatar asked May 27 '09 06:05

softwarematter


People also ask

How do I create a proxy for Web API?

Access the Create Proxy wizard, as described in Creating an API proxy using the UI previously in this section. In the Create Proxy wizard, click Reverse proxy (most common). To generate the proxy from an existing, valid OpenAPI Specification, click Use OpenAPI Spec.

What is proxy in Web API?

What is an API proxy? You expose APIs on Apigee by implementing API proxies. API proxies decouple the app-facing API from your backend services, shielding those apps from backend code changes. As you make backend changes to your services, apps continue to call the same API without any interruption.

What is HTTP proxy authentication required?

The HTTP 407 Proxy Authentication Required client error status response code indicates that the request has not been applied because it lacks valid authentication credentials for a proxy server that is between the browser and the server that can access the requested resource.


2 Answers

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

<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

<system.net>
  <defaultProxy enabled="true" useDefaultCredentials="true">
    <proxy/>
    <bypasslist/>
    <module/>
  </defaultProxy>
</system.net>
like image 141
abhilash Avatar answered Oct 25 '22 19:10

abhilash


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,e.g:

WebClient client = new WebClient();
client.proxy= proxy;

like image 34
kusnaditjung tjung Avatar answered Oct 25 '22 17:10

kusnaditjung tjung