62,244
社区成员




public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
HttpClientHandler handler = new ()
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
HttpClient hc = new(handler);
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async httpContext =>
{
if (httpContext.Request.Query.ContainsKey("url"))
{
string url = httpContext.Request.Query["url"];
HttpResponseMessage r = hc.GetAsync(url).Result;
httpContext.Response.ContentType =
(string.IsNullOrWhiteSpace(r.Content.Headers.ContentType.MediaType) ? "application/json" : r.Content.Headers.ContentType.MediaType)
+ "; charset=" +
(string.IsNullOrWhiteSpace(r.Content.Headers.ContentType.CharSet) ? "UTF-8" : r.Content.Headers.ContentType.CharSet);
await httpContext.Response.WriteAsync(await r.Content.ReadAsStringAsync());
}
else
{
await httpContext.Response.WriteAsJsonAsync(new { err = "empty url" });
}
});
});
}