如何使用http发布上传文件?德尔福2009 [英] How do I upload a file using http post? Delphi 2009
问题描述
我的目标是通过HTTP帖子上传文本文件,而我正在使用Delphi 2009。
My goal is to upload a text file via HTTP post I am using Delphi 2009.
例如说到以下URL
https://www.example.com/ex/exampleAPI.asmx/Process
我知道可以使用TIdHttp组件来完成。接下来的调用
I understand it can be done by using the TIdHttp component. And the following call
IdHttp1.Post();
但是我不知道如何设置所有内容,即指定url并包括要发布的文件。
But I cant figure out how to set up everything i.e. specifying the url and including the file to be posted.
谢谢。
推荐答案
TIdHTTP
有两个 Post()
的重载版本,它们以文件名作为输入:
TIdHTTP
has two overloaded versions of Post()
that take a filename as input:
var
Response: String;
Response := IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt');
。
var
Response: TStream;
Response := TMemoryStream.Create;
IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt', Response);
...
Response.Free;
请注意,您要发布到 HTTPS
URL,因此您需要先将启用SSL的IOHandler(例如 TIdSSLIOHandlerSocketOpenSSL
)分配给 TIdHTTP.IOHandler
属性
Note that you are posting to an HTTPS
URL, so you need to first assign an SSL-enabled IOHandler, such as TIdSSLIOHandlerSocketOpenSSL
, to the TIdHTTP.IOHandler
property beforehand.
这篇关于如何使用http发布上传文件?德尔福2009的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!