【发布时间】:2020-07-26 23:30:22
【问题描述】:
如何将 HTML webform 的参数转换为在 Delphi 中与 TIdHTTP 一起使用?
我有一个带有 PHP 的 Web 服务器和一个上传文件的功能。通过网络浏览器,我可以毫无问题地发送文件,但是当我使用 TIdHTTP 时,它会出现错误。
这是文件上传页面的 HTML:
<html>
<head>
<title>Upload de Arquivos com PHP</title>
</head>
<body>
<form method="post" action="recebe_upload.php" enctype="multipart/form-data">
<label>Arquivo:</label>
<input type="file" name="arquivo" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
这是我用来发送文件的过程:
procedure TForm1.Button1Click(Sender: TObject);
var
Response, URL : String;
LHTTPClient : TIdHTTP;
Lista : TIdMultiPartFormDataStream;
server, script, caminhoarq : string;
begin
URL := 'http://192.168.15.101/RECEBE_UPLOAD.php\';
Lista := TIdMultiPartFormDataStream.Create;
HTTPClient := TIdHTTP.Create;
HTTPClient.ProtocolVersion := pv1_1;
HTTPClient.Request.ContentType := 'utf-8';
HTTPClient.Request.UserAgent := 'Mozilla/3.0 (compatible;Indy Library)';
HTTPClient.HTTPOptions := [hoForceEncodeParams, hoKeepOrigProtocol];
Response := '';
try
try
Lista.AddFormField('Arquivo','C:\Client\teste.txt');
Response := UTF8Decode(Trim(HTTPClient.Post(URL, Lista)));
memo1.Lines.add(response);
except
on e : exception do
ShowMessage('Erro ao enviar arquivo ao servidor! Detalhes: '+e.Message);
end;
finally
Lista.Free;
HTTPClient.free;
end;
end;
这是我收到的错误消息:
<br />
<b>Notice</b>: Undefined index: arquivo in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>: Undefined index: arquivo in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>30</b><br />
<br />
<b>Strict Standards</b>: Only variables should be passed by reference in <b>C:\xampp\htdocs\RECEBE_UPLOAD.php</b> on line <b>30</b><br />
【问题讨论】:
标签: php delphi upload transfer idhttp