THttprio onBeforeExecute 更改soapRequest

发布于 2024-09-01 08:49:33 字数 581 浏览 4 评论 0原文

我已经为一个项目导入了一些 wsdl 。 我想更改 HttpRio onBeforeExecute 事件上的 SoapRequest,但是 当我更改请求时,我收到一些错误,如何更改请求 xml 文件 在此事件上使用 stringReplace 函数。

我尝试过更改流的大小,更改了编码等,但无论如何它都不起作用。

例子

procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;

I've imported some wsdl for a project.
i want to change the SoapRequest on HttpRio onBeforeExecute event, but
as i changed the request, im getting some errors how can i change the request xml file
with stringReplace function on this event.

i've tried to change the size of stream, i ve changed the encoding etc. but anyway it didnt work.

example

procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨夜星沙 2024-09-08 08:49:33
procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
   **SOAPRequest.Postion:=0**;// i forget this here, as i write the code that worked
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;
procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
   **SOAPRequest.Postion:=0**;// i forget this here, as i write the code that worked
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;
秋意浓 2024-09-08 08:49:33

可能的增强...我发现,根据我的情况(这是在肥皂响应中,顺便说一句,以防万一),如果生成的请求比原始请求短(在您的情况下是这样),则存在 CRUD当新字符串写回到流中时留下的内容。
ex:

original: <blablaa some stuff>
intended: <bla some stuff>
actual:   <bla some stuff>uff>

Fix:

SOAPRequest.Postion:=0;// 我在这里忘记了这一点,因为我编写了有效的代码
SOAPRequest.size := length(sTmp.Text); // 重要 - 在保存之前设置新长度。
sTmp.SaveToStream(SOAPRequest);

Possible enhancement... I found, with my situation (and this was in the soap response, btw, in case it matters), that if the resulting request is shorter than the original (and in your case it is), there was crud left over when the new string is written back out to the stream.
ex:

original: <blablaa some stuff>
intended: <bla some stuff>
actual:   <bla some stuff>uff>

Fix:

SOAPRequest.Postion:=0;// i forget this here, as i write the code that worked
SOAPRequest.size := length(sTmp.Text); // Important - set new length before saving.
sTmp.SaveToStream(SOAPRequest);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文