1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
app.Run(async (context) =>
{
NetworkCredential creds = new NetworkCredential
{
Domain = "Domain",
UserName = "User",
Password = "Pwd"
};
WebProxy proxy = new WebProxy
{
Address = new Uri("http://foo.bar/proxy.pac"),
Credentials = creds
};
HttpClientHandler handler = new HttpClientHandler
{
UseProxy = true,
Proxy = proxy
};
HttpClient client = new HttpClient(handler, true);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "apiPwd");
string destAPIUrl = "https://api.blabla.com/function?param1=30¶m2=10¶m3=43";
HttpResponseMessage response = client.GetAsync(destAPIUrl).Result;
if (response.IsSuccessStatusCode)
await context.Response.WriteAsync(await response.Content.ReadAsStringAsync());
else
await context.Response.WriteAsync(response.StatusCode.ToString() + " : " + response.ReasonPhrase);
});
} |
Partager