HttpClient를 사용하여 C#에서 특정 URL로 POST 요청 (somethis url에서 검색)을 시도하고 인코딩에 문제가 있습니다. "test"(코드 아래) 값 괜찮아요, 나에게 검색 결과를 제공하고, 다른 알파벳 ("тест")으로 된 단어는 나에게 결과를주지 않습니다.POST 요청 매개 변수 값의 인코딩
그런데 사이트 검색은 모든 단어와 잘 작동합니다. 첫 번째 경우 Firefox (요소 검사 -> 네트워크 -> POST 요청 -> 매개 변수)는 search : test와 같은 매개 변수를 표시하고 두 번째 경우에는 search : òåñò를 표시합니다. "тест"대신 "òåñò"를 보내려고했습니다. 성공하지 못했습니다. 내가 뭘 잘못하고있어? 도와주세요.
try
{
using (var httpClient = new HttpClient())
{
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, url);
httpRequestMessage.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36");
httpRequestMessage.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml");
List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();
KeyValuePair<string, string> param = new KeyValuePair<string, string>("search", "test");
parameters.Add(param);
HttpContent httpContent = new FormUrlEncodedContent(parameters);
httpRequestMessage.Content = httpContent;
var response = await httpClient.SendAsync(httpRequestMessage).ConfigureAwait(false);
var responseBody = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
string respBodyEncoded = encoding.GetString(responseBody);
}
}
catch
{
}