简体   繁体   English

在C#可移植类库中使用代理(Microsoft.Net.Http)

[英]Use Proxy in C# Portable Class Library (Microsoft.Net.Http)

I would like to know how to use a Proxy in a HttpWebRequest within a Portable Class Library (PCL). 我想知道如何在可移植类库(PCL)中的HttpWebRequest中使用代理。

I read here that the IWebProxy interface did not have any implementation within the Microsoft.Net.Http library. 在这里读到IWebProxy接口在Microsoft.Net.Http库中没有任何实现。

I need my HttpWebRequest to use a WebProxy. 我需要我的HttpWebRequest来使用WebProxy。 Any idea on how to do this in a PCL? 有关如何在PCL中执行此操作的任何想法?

Thanks for the help 谢谢您的帮助

It seems you can use your own implementation of IWebProxy (I haven't tested it on WinRT, but it works on the desktop with HttpClient ) 看来你可以使用自己的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;
    }
}

HttpClient似乎存在于PCL中,可以像这样使用使用.NET 4.5 HttpClient代理 (如果我正确看到,你可以在这里找到答案)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM