. net 5 HttpClient无法获取html内容页- http 500



我试图使用HttpClient来获取页面的html内容。尝试我用google URL测试的方法,它正在工作,我收到了我的html页面的内容。但是用我想要的url,不可能得到一个内容。我每次都有一个返回代码http 500。问题是,我可以得到我的文件的内容与邮差,甚至与python,但不可能与。net 5

有人知道吗?提前谢谢你。

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);
}
}

像这样指定User-Agent

client.DefaultRequestHeaders.Add("User-Agent", "C# console program");

在HttpResponseMessage response = await client之前。GetAsync

最新更新