Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send parameters via HTTP POST?

Status
Not open for further replies.

DVirus

Programmer
Oct 5, 2002
8
TR
Hi.. I'm trying to send a file to my server (which receives via php uploader).. But I couldn't get success on it..

I tried Indy IdHTTP component.. It's connected but I couldn't manage to send correct headers.. You can see it below.. Where's the mistake? Please check it..
And why " Params.Write(S[1], Length(S));" had written??
S is a long string but writes only one char but full length?? I also tried (S, ...) form but not worked again..

PHP script is also here, and it works when I used from a real HTTP page and FORM with two fields... But unfortunately I did not send headers from delphi project :(

There's a little example I found on the net.. What must I do to gain file-send option with this project?

--------------------------example-------------------------
procedure TForm1.SendPostData;
const
CRLF = #13#10;
var
aStream: TMemoryStream;
Params: TMemoryStream;
S: string;
begin
aStream := TMemoryStream.create;
Params := TMemoryStream.Create;

HTTP.Request.ContentType := 'multipart/form-data; boundary = -----------------------------7cf87224d2020a';

try
S := '-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="test1"' + CRLF + CRLF +
'file one content.' + CRLF +
'-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="test2"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf87224d2020a--';

Params.Clear;
Params.Write(S[1], Length(S));

with HTTP do
begin
try
HTTP.Post(' Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
-------------------------example ends----------------------
-------------------------php test file---------------------
<?php
print &quot;1: $test1\n<BR>&quot;;
print &quot;2: $test2\n<BR>&quot;;
?>
-----------------------php test file ends------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top