* * *

Author Topic: Send file (POST method) to a https web server  (Read 695 times)

cpalx

  • Hero Member
  • *****
  • Posts: 565
Send file (POST method) to a https web server
« on: March 01, 2018, 03:40:30 am »
I need to send a file to a Secure Web server (https) using POST method
i found a code to send with synapse but it doesnt work with https. Any Idea?

Code: Pascal  [Select]
  1.  
  2. function TForm1.MyHttpPostFile(const URL, FieldName, FileName: string;
  3.   const Data: TStream; const ResultData: TStrings): Boolean;
  4. var
  5.   HTTP: THTTPSend;
  6.   Bound, s: string;
  7. begin
  8.   Bound := IntToHex(Random(MaxInt), 8) + '_Synapse_boundary';
  9.   HTTP := THTTPSend.Create;
  10.   try
  11.     s := '--' + Bound + CRLF;
  12.     s := s + ' content-disposition: form-data; name="' + FieldName + '";';
  13.     s := s + ' filename="' + FileName +'"' + CRLF;
  14.     s := s + ' Authorization: ' + ediTOKEN.Text+ CRLF;
  15.     s := s + ' Content-Type: Application/octet-string' + CRLF + CRLF;
  16.     WriteStrToStream(HTTP.Document, s);
  17.     HTTP.Document.CopyFrom(Data, 0);
  18.     s := CRLF + '--' + Bound + '--' + CRLF;
  19.     WriteStrToStream(HTTP.Document, s);
  20.     HTTP.MimeType := 'multipart/form-data; boundary=' + Bound;
  21.     Result := HTTP.HTTPMethod('POST', URL);
  22.     if Result then
  23.       ResultData.LoadFromStream(HTTP.Document)
  24.     else
  25.       ResultData.Text:= 'Error Code:' + IntToStr(HTTP.ResultCode);
  26.   finally
  27.     HTTP.Free;
  28.   end;
  29. end;                                          
  30.  

Renat.Su

  • Jr. Member
  • **
  • Posts: 70
    • Renat.Su
Re: Send file (POST method) to a https web server
« Reply #1 on: March 01, 2018, 09:42:32 am »
Other methods work? GET, for example. If not, then surely something is not so configured with OpenSSL. Do you have any libraries folder? If there is, try deleting. If not, add it to the folder. ) Do not forget to add ssl_openssl to the Uses block

cpalx

  • Hero Member
  • *****
  • Posts: 565
Re: Send file (POST method) to a https web server
« Reply #2 on: March 01, 2018, 11:20:59 pm »
My fault, i didnt:


Code: Pascal  [Select]
  1.   HTTP.Sock.CreateWithSSL( TSSLOpenSSL );

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus