Delphi Devart SecureBridge POST 请求

标签 delphi delphi-xe devart

我正在使用 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/

相关文章:

delphi - 在 Delphi 中启动 Word x64

delphi - 编译此函数时没有响应?

mysql - 无法仅使用代码连接到 mySql 数据库

delphi - Raise 错误在带有 Sybase 12.5 客户端库的 Unidac 组件中不起作用

c# - 如何使用 C# 调用接收 Delphi 开放数组参数的函数?

Delphi SysUtils.Supports 意外返回 true

delphi - 了解从 tkSet 中选择的 tkEnumeration

delphi - Delphi 中的 SOAP 客户端 "The handle is in the wrong state for the requested operation"

delphi - 替换Delphi XE3中的RIDL文件和typelib

c# - 如何在 Oracle DB 中使用 DataTable(或类似的)