Tre*_*vor 8 delphi file-upload indy http-post delphi-2009
我的目标是通过HTTP post上传文本文件我正在使用Delphi 2009.
比如说以下网址
https://www.example.com/ex/exampleAPI.asmx/Process
我知道可以使用TIdHttp组件来完成.以下是电话
IdHttp1.Post();
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何设置所有内容,即指定网址并包含要发布的文件.
谢谢.
TIdHTTP有两个重载版本的Post()文件名作为输入:
var
Response: String;
Response := IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt');
Run Code Online (Sandbox Code Playgroud)
.
var
Response: TStream;
Response := TMemoryStream.Create;
IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt', Response);
...
Response.Free;
Run Code Online (Sandbox Code Playgroud)
请注意,您要发布到HTTPSURL,因此您需要先预先TIdSSLIOHandlerSocketOpenSSL为该TIdHTTP.IOHandler属性分配启用SSL的IOHandler,例如.