The ServicePointManager does not support proxies with the localhost scheme

When making HttpWebRequest or WebRequest call in C#, we might be getting “The ServicePointManager does not support proxies with the localhost scheme” error. It is due to web.config using wrong proxy node or invalid proxy information.

In that case we need to reset or override the web.config proxy information in HttpWebRequest or WebRequest call to avoid such errors.

Here is example code to be used before the initialization of HttpWebRequest or WebRequest object.

HttpWebRequest.DefaultWebProxy = new WebProxy();
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);

or

WebRequest.DefaultWebProxy = new WebProxy();
WebRequest myWebRequest = WebRequest.Create(url);

This code will solve the problem “The ServicePointManager does not support proxies with the localhost scheme” error.

Leave a Reply

Your email address will not be published. Required fields are marked *

*