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