最近将程序从 Delphi 2006 转换为 XE3,我遇到了 TidHttp 问题。这是代码:
Result := '';
myCurrentTime := FormatDateTime('yyyymmddhhnnss',now);
myParams := '<params>';
myParams := myParams + '<licence>' + '1234567890' + '</licence>';
myParams := myParams + '<activationcode>' + 'abcdef' + '</activationcode>';
myParams := myParams + '<devicename>' + 'aaa' + '</devicename>';
myParams := myParams + '<deviceid>' + 'bbb' + '</deviceid>';
myParams := myParams + '<devicetimestamp>' + myCurrentTime + '</devicetimestamp>';
myParams := myParams + psRequest;
myParams := myParams + '</params>';
myRequestStream := nil;
myResponseStream := nil;
myHTTP := nil;
myXMLDocument := nil;
finished := false;
myAttempts := cAttempts;
while finished = false do
begin
try
myRequestStream := TMemoryStream.Create;
myResponseStream := TMemoryStream.Create;
myHTTP := TIdHTTP.Create;
myXMLDocument := TXMLDocument.Create(nil);
myParams := mEncoder.Encode(myParams);
myRequestStream.Write(myParams[1], Length(myParams));
myRequestStream.Position := 0;
myHTTP.Request.Method := 'POST';
myHTTP.ReadTimeout := piTimeoutSeconds * 1000;
myHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
myHTTP.Request.ContentLength := myRequestStream.Size;
myHTTP.ProtocolVersion := pv1_1;
myHTTP.Post(psUrl, myRequestStream, myResponseStream);
在帖子之后,我收到错误“引发的异常是 Base 64 字符串中的无效字符”-在错误处理例程中报告为“{”。
我一直在网上搜索,但找不到答案。任何建议将不胜感激。
谢谢。
史蒂夫