5

Saldiert 4,5 wir mit Proxy wie folgt arbeiten:asp.net Kern default

<system.net> 
    <!-- --> 
    <defaultProxy enabled="true" useDefaultCredentials="false"> 
     <proxy usesystemdefault="True" proxyaddress="http://192.168.1.1:8888" bypassonlocal="True" autoDetect="False" /> 
     <module type="CommonLibrary.Proxy.MyProxy, CommonLibrary, Version=1.0.0.0, Culture=neutral" /> 
    </defaultProxy> 

    <settings> 
     <httpWebRequest useUnsafeHeaderParsing="true" /> 
     <servicePointManager expect100Continue="false" /> 
    </settings> 
</system.net> 

aber in asp.net Kern oder Test, den wir nicht eine Lösung wie die oben gefunden können Könnte mir jemand bitte helfen ?

Ich schätze Ihre Hilfe

Dank, Grüße

Antwort

4

Sie sollten wirklich eine Middleware verwenden. Haben Sie einen Blick auf diese:

https://github.com/aspnet/Proxy

gibt es einen 'Proben' -Ordner: https://github.com/aspnet/Proxy/tree/dev/samples/Microsoft.AspNetCore.Proxy.Samples

Weitere Ressourcen zum Thema: http://josephwoodward.co.uk/2016/07/proxying-http-requests-asp-net-core-using-kestrel

http://overengineer.net/creating-a-simple-proxy-server-middleware-in-asp-net-core

funktioniert ein Middleware funktioniert für Sie?

+0

Hallo. Ich brauche defaultProxy, weil ich einen Client habe, der über einen Proxy mit der IP-Adresse auf der Whitelist meines Providers validiert ist. –

4

Um ein HTTP-Proxy in .net Kern zu verwenden, müssen Sie IWebProxy interface.This ist vom System.Net.Primitives.dll assembly.You kann es dd project.json wenn nicht bereits vorhanden

implementieren z.B

"frameworks": { 
    "dotnet5.4": { 
     "dependencies": { 
     "System.Net.Primitives": "4.3.0" 
     } 
    } 
} 

Die Umsetzung ist sehr trivial

public class MyHttpProxy : IWebProxy 
    { 

     public MyHttpProxy() 
     { 
      //here you can load it from your custom config settings 
      this.ProxyUri = new Uri(proxyUri); 
     } 

     public Uri ProxyUri { get; set; } 

     public ICredentials Credentials { get; set; } 

     public Uri GetProxy(Uri destination) 
     { 
      return this.ProxyUri; 
     } 

     public bool IsBypassed(Uri host) 
     { 
      //you can proxy all requests or implement bypass urls based on config settings 
      return false; 

     } 
    } 


var config = new HttpClientHandler 
{ 
    UseProxy = true, 
    Proxy = new MyHttpProxy() 
}; 

//then you can simply pass the config to HttpClient 
var http = new HttpClient(config) 

Kasse https://msdn.microsoft.com/en-us/library/system.net.iwebproxy(v=vs.100).aspx

+0

Vielen Dank. Wie kann ich das für den WCF-Client tun? –

+0

Hallo. Ich brauche defaultProxy, weil ich einen Client habe, der über einen Proxy mit der IP-Adresse auf der Whitelist meines Providers validiert ist. –

+0

@MarceloOliveto verwenden Sie Client-orientierte WCF-Bibliotheken in .net-Core? sieht so aus, als ob es immer noch keine Proxies unterstützt, da ist ein Problem dafür geöffnet https://github.com/dotnet/wcf/issues/1592 –