我正在尝试使用库THTTPSendEx上传文件。
我的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
HTTP:THTTPSendEx;
Data:TMultipartFormDataStream;
sHTML:string; //Recived HTML code from web
begin
if OpenDialog1.Execute then
begin
HTTP:=THTTPSEndEx.Create;
Data:=TMultipartFormDataStream.Create;
try
Data.AddFile('myFile', OpenDialog1.FileName);
Data.DataEnd;
if HTTP.Post('http://kaon.rghost.ru/files',Data,sHTML) then
begin
//Connection established
//Check HTTP response
if HTTP.IsSuccessfull then //HTTP returns "200 OK" code.
begin
ShowMessage('File successfully posted to the server.');
end;
end else
begin
ShowMessage('Can not establish a connection to the server...'+#13+'Network is not avaliable or server socket does not exist.');
end;
finally
FreeAndNil(HTTP);
FreeAndNil(Data);
end;
end;
end;
但没有打印。提示出现了什么问题?
我很抱歉翻译不好,我使用了Google Translater
更新:
php的工作示例:
$ url = 'http://kaon.rghost.ru/files';
$ FILENAME = 'add.png';
$ files = array ('file' => '@'. $ FILENAME);
$ useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.9.0.3) Gecko/2008092417 Firefox/3.0.3';
$ ch = curl_init ($ url);
curl_setopt ($ ch, CURLOPT_HTTPHEADER, array ("Content-type: multipart / form-data"));
curl_setopt ($ ch, CURLOPT_HEADER, 1);
curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ ch, CURLOPT_USERAGENT, $ useragent);
curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ files);
$ response = curl_exec ($ ch);
echo $ response;
答案 0 :(得分:0)
对于文件发布,任何网站都需要cookie和/或post params和/或文件的有效输入字段名称。这是将文件发布到服务器的最低要求。
您只需复制示例,粘贴您的网址并将文件加载到流中。不,这没有用。
我没有看到rghost.ru在您的代码中发布文件所需的任何内容。