作者:浅浅的思恋的小媳妇 | 来源:互联网 | 2023-07-10 10:07
我正在使用C#开发Web服务。客户端工作正常,但是如果参数包含土耳其语字符,则结果为null。
我知道这是一个编码问题,但我不知道如何设置。
我为HttpClient尝试了以下操作:
httpClient.DefaultRequestHeaders.acceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));
httpClient.DefaultRequestHeaders.acceptEncoding.Add(new StringWithQualityHeaderValue("windows-1254"));
httpClient.DefaultRequestHeaders.acceptLanguage.Add(new StringWithQualityHeaderValue("tr-TR"));
但是没有用。我以为也许我在参数中编码土耳其语字符,反过来又尝试了:
HttpUtility.UrlEncode(district);
Uri.EscapeUriString(district);
Uri.EscapeDataString(district);
,但此操作不再起作用。我的代码块如下:
private HttpClient getclient() {
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(Configurationmanager.AppSettings["ServiceBaseUrl"]);
httpClient.DefaultRequestHeaders.accept.Clear();
httpClient.DefaultRequestHeaders.accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
httpClient.DefaultRequestHeaders.acceptEncoding.Add(new StringWithQualityHeaderValue("windows-1254"));
return httpClient;
}
public SupportPersonDto GetSupportPersonList(string city,string district) {
SupportPersonDto serviceResult = null;
string param = "" +
"" + Configurationmanager.AppSettings["serviceUser"] + "" +
"" + Configurationmanager.AppSettings["servicePass"] + "" +
"" + city + "" +
"" + district + "" +
"";
HttpClient httpClient = getclient();
string apiUrl = "?xmlData=" + param;
HttpResponseMessage respOnse= httpClient.Getasync(apiUrl).Result;
if (response.IsSuccessStatusCode) {
var stream = response.Content.ReadAsStreamAsync();
stream.Wait();
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "NGDIRECTORY";
xRoot.Isnullable = true;
XmlSerializer serializer = new XmlSerializer(typeof(SupportPersonDto),xRoot);
serviceResult = (SupportPersonDto)serializer.Deserialize(stream.Result);
}
httpClient.Dispose();
return serviceResult;
}
有人可以帮我吗?
非常感谢所有帮助过的人。
Daniel和Lasse都建议我使用UrlEncode,这是正确的答案。
解决了如下问题,可以编辑代码:
pq.write_table(pa.Table.from_dataframe(pandas.DataFrame))
这么多天后:)
再次感谢您的帮助