THttprio onBeforeExecute changing soapRequest

I imported some wsdl for the project. I want to change SoapRequest to the HttpRio onBeforeExecute event, but as I changed the request, I get some errors, how can I change the XML request file with the stringReplace function in this event.

I tried to resize the stream, I changed the encoding, etc., but in any case, it did not 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; 
+4
source share
2 answers
 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; 
+3
source

Possible improvement ... I found that with my situation (and this was in response to soap, by the way, in case it matters), that if the received request is shorter than the original (and in your case it is), after as a new line is written back to the stream, crud was heard.
ex:

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

Fix:

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

+5
source

Source: https://habr.com/ru/post/1309483/


All Articles