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 "1: $test1\n<BR>";
print "2: $test2\n<BR>";
?>
-----------------------php test file ends------------------
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 "1: $test1\n<BR>";
print "2: $test2\n<BR>";
?>
-----------------------php test file ends------------------