https://nayapatrikadaily.com/news-article/2/News
我正在尝试使用 Http请求从新闻网站获取 html 内容Post
。
但是在响应中,页面返回 Unicode 字符。
我在将 Unicode 字符转换为 html 时遇到了阻碍。
网址:
var nayapatrika = await ApiClient.PostAsync("https://nayapatrikadaily.com/ajax/pagination.php");
异步后:
public static async Task<HtmlDocument> PostAsync(string uri)
{
string responseJson = string.Empty;
var htmlDocument = new HtmlDocument();
var handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
var content = new MultipartFormDataContent();
var values = new[]
{
new KeyValuePair<string, string>("perPage", "20"),
new KeyValuePair<string, string>("page", "2"),
new KeyValuePair<string, string>("cat", "1"),
};
foreach (var keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
}
var response = await client.PostAsync(uri, content);
if (response.IsSuccessStatusCode)
{
responseJson = await response.Content.ReadAsStringAsync();
htmlDocument.LoadHtml(responseJson);
}
}
return htmlDocument;
}
响应时,页面始终返回以下字符。
元芳怎么了
相关分类