Wednesday 15 May 2013

Error 407 Proxy Authentication Required In SharePoint

If you don't want to put passwords into your web.config for the proxy, you can do so programatically and skip the error 407 in SharePoint. Here's how.

You, like me, have probably struggled on numerous occasions to get a SharePoint webpart to connect to a different website / webservice, such as google api or twitter api, and failed because you came across the error: "The remote server returned an error: (407) Proxy Authentication Required".
I tried modifying the web.config but this didn't work, I tried adding the proxy with usedefaultcredentials = true, but this didn't work either.
If you've gone this far and nothing is working for you, this is how it's done.
1.         Uri myUri = new Uri("http://www.example.com");

2.         WebRequest myWebRequest = WebRequest.Create(myUri);

3.         WebProxy proxy = new WebProxy("http://webproxy.mydomain.com:8080", true);

4.         System.Net.NetworkCredential credentials = new NetworkCredential("sharepoint.user", "password", "logon_domain");

5.         proxy.UseDefaultCredentials = false;

6.         proxy.Credentials = credentials;

7.         myWebRequest.Proxy = proxy;

8.         WebResponse myWebResponse = myWebRequest.GetResponse();

9.         output.Write(myWebResponse.Headers.ToString());

Instead of trying to use the credentials of the current user, an account is specified that allows access to the proxy.
I'd tried everything and this was the only thing that worked for me, I hope it helps you too.

No comments:

Post a Comment

Rescan Disk Option Greyed Out | New Disks Not visible on Disk management | Update-HostStorageCache

  Recently I have added several LUN from NetApp Storage to Hyper-V servers. But in the disk management I couldn't see those new LUN. Exi...