我正在使用 DevArt 的 SecureBridge 产品的试用版。我正在尝试处理 POST,但不知何故我无法打印请求数据。
XML:
<test>
<a>test1</a>
<b>test2</b>
</test>
德尔福:
ScHttpWebRequest1.Method := rmPOST;
ScHttpWebRequest1.ContentType := 'text/xml';
ScHttpWebRequest1.RequestUri := 'https://test.com/api';
ScHttpWebRequest1.KeepAlive := True;
ScHttpWebRequest1.ContentLength := Length(XML);
ScHttpWebRequest1.WriteBuffer(pAnsiChar(XML), 0, Length(XML)); ///I think I'm making a mistake here.
ShowMessage(ScHttpWebRequest1.GetResponse.ReadAsString);
我已经查看了文档,但是有一个称为RequestStream的功能。我下载的版本中没有此功能。我认为WriteBuffer是用来代替或者不同的。我想做的就是在相关站点上请求包含 XML 内容的 POST。我该怎么做?
谢谢。
最佳答案
这是一段对我有用的代码:
var
Response: TScHttpWebResponse;
ResponseStr: string;
buf: TBytes;
begin
ScHttpWebRequest1.Method := rmPOST;
ScHttpWebRequest1.ContentType := 'text/xml';
ScHttpWebRequest1.RequestUri := 'https://test.com/api';
ScHttpWebRequest1.KeepAlive := True;
buf := TEncoding.UTF8.GetBytes(xml);
ScHttpWebRequest1.ContentLength := Length(buf);
ScHttpWebRequest1.WriteBuffer(buf);
Response:=ScHttpWebRequest1.GetResponse;
ResponseStr:=Response.ReadAsString;
end;
关于Delphi Devart SecureBridge POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62793110/