62,268
社区成员
发帖
与我相关
我的任务
分享
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" });
}
});
});
}








是我的错!!!是我的错!!!是我的错!!!是我的错!!!
经 Fiddler 抓包,发现在两台机器上的数据包都一样,可以肯定不是环境和程序的事儿了。又在服务器上的浏览器上试了试,果然出现了出错的页面,原来的确是那个页面和服务器地址没有授权,可能是我之前试的时候把本机的响应结果当成服务器的了.....自已把自己给坑了....
感谢楼上各位!!!