【发布时间】:2021-10-15 17:55:13
【问题描述】:
我正在尝试使用 HttpClient 来获取页面的 html 内容。 尝试我用谷歌 URL 测试的方法,它正在工作,我收到了我的 html 页面的内容。 但是有了我想要的 url,就不可能得到内容。我每次都有一个返回码 http 500。 问题是,我可以使用 POSTMAN 甚至使用 python 获取文件的内容,但使用 .NET5 是不可能的
有人有想法吗? 提前谢谢你。
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
try
{
HttpResponseMessage response = await client.GetAsync("https://www.naeu.playblackdesert.com/fr-FR/Adventure/Profile?profileTarget=tbXSK7e39Sb3U3yPi7UDjjSeXLzr0HZbr%2bvZQYvtEENKNEz6zPFwtpkvp0pIir%2fk%2fWk7JFLXKICyzqEBwajIrTCHQPFH4MRyBkor2fVeMAb8hNGoasy8HtBiHlcoWN1xRsmmYjVt6WbJg2ocvr%2fbsQk2sbjKeD5a7VqgreAH0ztzMvoFqk7Z%2fZ7L4USyu5Up");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch(HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ",e.Message);
}
}
【问题讨论】:
标签: c# httpclient .net-5 html-content-extraction