WebProxy on Portable Class Library

I am creating a portable class library project. Using the HttpClient class (installed from NuGet packages).

Now. I want to make an HttpClient using a proxy by passing the HttpClientHandler constructor to it (HttpClientHandler has a Proxy attribute, we will assign a WebProxy instance to it). The problem is that the Portable Class Library does not support the WebProxy class. It only has an IWebProxy interface.

I have searched on Google, NuGet Package, but I cannot find a solution for this case. Please, say Me. How can I solve this (or another way to make the HttpClient using a proxy)

+1


source to share


1 answer


There is no PCL implementation of IWebProxy, but it is a very simple interface that you can easily implement yourself. Something like this for the same proxy for all directions:



public class Proxy : System.Net.IWebProxy
{
    public System.Net.ICredentials Credentials
    {
        get;
        set;
    }

    private readonly Uri _proxyUri;

    public Proxy(Uri proxyUri)
    {
        _proxyUri = proxyUri;
    }

    public Uri GetProxy(Uri destination)
    {
        return _proxyUri;
    }

    public bool IsBypassed(Uri host)
    {
        return false;
    }
}

      

+5


source







All Articles