Synapse HTTPServ Delphi 7问题

时间:2014-06-20 16:20:59

标签: delphi http synapse

我尝试使用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获取以下函数的结果,并根据作者的注释,InputData应保存上传的文件。

它没有 - 显然是因为大小总是= 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>

有关为何会这样做的任何想法?

1 个答案:

答案 0 :(得分:1)

您的HTML网络表单无法使用method="get"上传文件,但必须使用method="post"。 HTTP GET请求不包含任何正文数据,但POST会执行。{/ p>