Я пытаюсь сделать следующее с легко доступным примером Synapse HTTPServ в Delphi 7.
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
Звучит просто.. на бумаге.
В файле http.pas в процедуре TTCPHttpThrd.Execute показан следующий код.
//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>
Любые мысли о том, почему это может быть?