【发布时间】:2012-03-24 19:00:00
【问题描述】:
我正在尝试使用 indy (HTTP Post) 恢复上传,代码如下所示(使用 Delphi 2010,Indy 10.4736):
IdHttp.Head('http://localhost/_tests/resume/large-file.bin');
ByteRange := IdHttp.Response.ContentLength + 1;
// Attach the file to post/upload
Stream := TIdMultipartFormDataStream.Create;
with Stream.AddFile('upload_file', 'D:\large-file.bin', 'application/octet-stream') do
begin
HeaderCharset := 'utf-8';
HeaderEncoding := '8';
end; // with
with IdHTTP do
begin
IOHandler.LargeStream := True;
with Request do
begin
ContentRangeStart := ByteRange;
ContentRangeEnd := (Stream.Size - ByteRange);
ContentLength := ContentRangeEnd;
ContentRangeInstanceLength := ContentLength;
end; // with
Post('http://localhost/_tests/resume/t1.php', Stream);
end; // with
但上传简历不起作用:(
我查看了Indy的代码,似乎IdIOHandler.pas
中的这个函数TIdIOHandler.Write()
始终处理完整的流/文件(因为参数 ASize: TIdStreamSize 似乎始终为 0,根据代码表示发送完整的文件/流)。
这会阻止 indy 恢复上传。
我的问题是:是否可以避免发送完整的文件?
设置内容范围没有改变任何东西。我还调整了 indy 的代码(修改了 3 行)以使 indy 遵守内容范围/流位置,但它有问题,并且 indy 总是挂在 IdStackWindows.pas 中,因为这里有无限超时:
TIdSocketListWindows.FDSelect()
【问题讨论】:
-
你应该使用
PUT。 -
这是remy lebeau said about put
-
不知道,他可能在谈论PHP4。但是,是的,您的愿望与 POST 不相容。
-
恢复文件与
PUT不兼容。我说了很多,另一方面,POST只是任意数据。接收脚本决定如何处理数据,因此理论上它可以用于恢复。在实践中,它很少。
标签: delphi post upload indy resume