Page 1 of 1

how to POST parameters

Posted: Tue 28 Jul 2020 14:00
by Yann
Hi, where can I find an example of how to use TScHttpWebRequest.RequestStream to transmit parameters ?
I'm using Delphi 7.
Thanks

Re: how to POST parameters

Posted: Fri 31 Jul 2020 15:22
by ViktorV
The RequestSteam property gets or sets a stream that is used to write the request data. This property can be only set if SendChunked is set to True and Method is not rmGET or rmHEAD. https://www.devart.com/sbridge/docs/ind ... stream.htm
If you mean something else, please clarify.

Re: how to POST parameters

Posted: Thu 12 Nov 2020 16:59
by docH
Four months and still no answer to the OP's question
where can I find an example of how to use TScHttpWebRequest.RequestStream
I have read the documentation and find it lacking, particularly in real life examples of use.
I'm also trying to find out how to POST parameters (as content type application/json).

Simply quoting the documentation in response to a question about it isn't very helpful

Re: how to POST parameters

Posted: Thu 19 Nov 2020 15:41
by ViktorV
You can use code like this to show the use of this property:

Code: Select all

var
  Request: TScHttpWebRequest;
  Response: TScHttpWebResponse;
  ResponseStr: string;
  Stream: TFileStream;
begin
  Request := TScHttpWebRequest.Create(URL);
  Stream := TFileStream.Create(FileName, fmOpenRead);
  try
    Request.Method := rmPut;

    Request.ContentType := 'application/pdf';
    Request.TransferEncoding := 'binary';
    Request.Headers.Add('Content-Disposition', 'form-data; name="FormFile"; filename="Document1.pdf"');

    Request.ContentLength := Stream.Size;
    Request.SendChunked := True;
    Request.RequestStream := Stream;

    Response := Request.GetResponse;
    ResponseStr := Response.ReadAsString;
    Response.Free;
  finally
    Stream.Free;
    Request.Free;
  end;
end;