【发布时间】:2020-11-20 17:57:43
【问题描述】:
我尝试模拟与此控制台调用相同的行为:
# curl -X POST -F"file=@myfile.csv" 'https://myserver/upload'
这是我的 Delphi 10.1 代码:
procedure TForm1.Button1Click(Sender: TObject);
var localfile:String;
localpath:string;
begin
localfile := 'myfile.csv';
localpath := 'C:\upload';
SetCurrentDir(localpath);
RESTClient.ContentType:= 'multipart/form-data';
RESTClient.BaseURL:= 'https://myserver';
RESTRequest.Accept:= '*/*';
RESTRequest.Method:= rmPOST;
RESTRequest.Resource:= 'upload';
RESTRequest.AddParameter('file',localfile, TRESTRequestParameterKind.pkREQUESTBODY);
RESTRequest.Execute;
Memo1.Lines.Add(RESTResponse.Content);
end;
它失败了:415 Unsupported Media Type
【问题讨论】:
-
您显示的 curl 命令行不执行 REST 请求,它是用于上传文件的简单 HTTP“POST”。您应该使用 HTTP 客户端组件。有很多可用的(我是 ICS 的作者:wiki.overbyte.be)。您的问题可能在那里得到解答:stackoverflow.com/questions/10889511/…
-
你救了我的命,非常感谢。