【发布时间】:2014-08-11 11:18:55
【问题描述】:
我正在尝试使用 Delphi 7 中现成的 Synapse HTTPServ 示例执行以下操作。
1) Generate a simple HTML page with upload form field
2) When the user fills in the field and clicks the button, the name of the
file is sent back to HTTPServ.
3) "get" the file and save locally
4) inspect the file
5) send back response with what was found
听起来很简单……在纸上。
在 TTCPHttpThrd.Execute 过程的 http.pas 文件中,显示如下代码。
//read request headers
If protocol <> '' then
Begin
If pos('HTTP/', protocol) <> 1 Then Exit;
If pos('HTTP/1.1', protocol) <> 1 Then close := true;
Repeat
s := sock.RecvString(Timeout);
If sock.lasterror <> 0 Then Exit;
If s <> '' Then Headers.add(s);
If Pos('CONTENT-LENGTH:', Uppercase(s)) = 1 Then Size := StrToIntDef(SeparateRight(s, ' '), -1);
// size ALWAYS returns 0 - CONTENT-LENGTH NOT IN HEADER!
If Pos('CONNECTION: CLOSE', Uppercase(s)) = 1 Then close := true;
// Present in header
Until s = '';
End;
// since size ALWAYS = 0 this never gets executed to "get" the file..
InputData.Clear;
If size >= 0 Then
Begin
InputData.SetSize(Size);
x := Sock.RecvBufferEx(InputData.Memory, Size, Timeout);
InputData.SetSize(x);
If sock.lasterror <> 0 Then Exit;
End;
OutputData.Clear;
ResultCode := ProcessHttpRequest(method, uri);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResultCode 获取以下函数的结果,根据作者 cmets 的说法,InputData 应该保存上传的文件。
它没有 - 显然是因为 size ALWAYS = 0。
function TTCPHttpThrd.ProcessHttpRequest(Request, URI: string): integer;
var
l: TStringlist;
begin
// sample of precessing HTTP request:
// InputData is uploaded document, headers is stringlist with request headers.
// Request is type of request and URI is URI of request
// OutputData is document with reply, headers is stringlist with reply headers.
// Result is result code
标题从不包含 CONTENT-LENGTH 字段。
所使用的表格非常简单:
<form name="getfile" action="http://127.0.0.1:80" method="get">
<input type="file" name="uploadedfile" />
<input type="submit" value="Submit" />
</form>
你有什么想法吗?
【问题讨论】: