how to POST parameters

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
Yann
Posts: 1
Joined: Tue 28 Jul 2020 13:53

how to POST parameters

Post by Yann » Tue 28 Jul 2020 14:00

Hi, where can I find an example of how to use TScHttpWebRequest.RequestStream to transmit parameters ?
I'm using Delphi 7.
Thanks

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: how to POST parameters

Post by ViktorV » Fri 31 Jul 2020 15:22

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.

docH
Posts: 59
Joined: Sun 22 Dec 2013 15:18

Re: how to POST parameters

Post by docH » Thu 12 Nov 2020 16:59

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

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: how to POST parameters

Post by ViktorV » Thu 19 Nov 2020 15:41

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;

Post Reply