3

我想知道如何在可移植类库 (PCL) 中的 HttpWebRequest 中使用代理。

我在这里读到IWebProxy 接口在 Microsoft.Net.Http 库中没有任何实现。

我需要我的 HttpWebRequest 才能使用 WebProxy。关于如何在 PCL 中执行此操作的任何想法?

谢谢您的帮助

4

2 回答 2

1

看来您可以使用自己的实现IWebProxy(我没有在 WinRT 上测试过,但它可以在桌面上使用HttpClient

class MyProxy : IWebProxy
{
    private readonly Uri _proxyUri;
    public MyProxy(Uri proxyUri)
    {
        _proxyUri = proxyUri;
    }

    public ICredentials Credentials { get; set; }
    public Uri GetProxy(Uri destination)
    {
        return _proxyUri;
    }
    public bool IsBypassed(Uri destination)
    {
        return false;
    }
}
于 2015-04-14T13:10:55.300 回答
0

HttpClient 似乎存在于 PCL 中,可以这样使用:Using a proxy with .NET 4.5 HttpClient(如果我没看错的话,你可能会在此找到答案)

于 2014-09-13T21:59:25.903 回答