HTTPRIO AfterExecute问题

时间:2011-05-19 16:33:30

标签: delphi

我认为在HTTPRio组件接收数据后,它会解析数据。我这样说是因为在程序离开AfterExecute程序之后,需要很长时间才能继续下一行代码。

我想要的是清除AfterExecute过程中到达的数据。这可能吗?

procedure TEventHandlers.thhoptAfterExecute(const MethodName: string;
  SOAPResponse: TStream);
var
  fs : TFileStream;
begin
  fs := TFileStream.Create('F:\Lixosam\LixoSMS'+
        IntToStr(ThCampanha),
            fmCreate, fmShareDenyNone);
  SOAPResponse.Position := 0;
  fs.CopyFrom(SOAPResponse, SOAPResponse.Size);
  fs.Free;
end;

如何清除数据,以便组件不必进行任何解析?

1 个答案:

答案 0 :(得分:3)

您可以将任何想要的内容写入SOAPResponse。您可以清除它,编辑它,无论如何。如果一个完全空的响应导致反序列化的麻烦(抱怨“文档必须有顶级元素,在第0行”),你可以坚持一个提供最小结构的“骨架”响应。如果编辑响应,则应相应地设置大小。 这是我的一些代码:

var
  sl : TStringList;

begin
  sl := TStringList.Create;
  try
    SOAPResponse.Position := 0;
    sl.LoadFromStream(SOAPResponse);    // Load the response into a stringlist so we can work on it.

    // some manipulation to the lines in sl occur here, such as stringreplaces and such.


    // Now write out edits back out to the stream.
    SOAPResponse.Position := 0;            // Now overwrite the crappy response with our good one.
    SOAPResponse.size := length(sl.Text);  // Important - set new length before saving.  Otherwise, the old
    sl.SaveToStream(SOAPResponse);         // leftover crud is still there, at the end, and the XML will blow up on it.

  finally
    FreeAndNil(sl);
  end;
end;