我遇到了一些特殊字符的问题,例如
ä
、ö
、ü
等在我的请求中显示为 �。
我像这样发送请求:
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
lBody: string;
lBody := '{"value": "testäöü"}';
RESTClient1 := TRESTClient.Create(myUrl);
RESTRequest1 := TRESTRequest.Create(RESTClient1);
RESTRequest1.Method := TRESTRequestMethod.rmPUT;
RESTRequest1.AddAuthParameter('Authorization', 'Bearer ' + mySessionId, pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.AddParameter('Content-Type', 'application/json; charset=utf-8', pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.AddParameter('Body', lBody, pkREQUESTBODY, [poDoNotEncode]);
RESTRequest1.Execute;
if RESTRequest1.Response.StatusCode <> 200 then
begin
// raise Exception
end;
如果我在调试器中查看 lBody,字符会正确显示,但是接收 REST 服务器(以及检查时的 fiddler)错误地显示我的 JSON:
{"value": "test���"}
。
而是使用以下内容来添加正文:
RESTRequest1.AddBody(lBody, 'application/json; charset=utf-8');