用NMHTTP如何写一个客户端,向服务器端的CGI发送一个二进制文件(非文本)?(50分)

  • 主题发起人 主题发起人 loxtln
  • 开始时间 开始时间
L

loxtln

Unregistered / Unconfirmed
GUEST, unregistred user!
用NMHTTP如何写一个客户端,向服务器端的CGI发送一个二进制文件(非文本)?CGI如何接收并处理之?
 
帮帮忙吧!我等着急用!
 
这个问题我自己解决了,谁进来拿分数?
 
能说说怎么做的么,如能把分再给了,那就再爽不过了,呵呵
 
客户端:
nmhttp1.OutputFileMode :=true;
nmhttp1.Post('http://xxx.xxx.xxx.xx/cgi/xxx.cgi?filename=ok.wav','c:/yy.wav');

CGI接收并处理:

procedure TWebModule1.WebModule1WebActionItem4Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
TotalBytes : DWORD;
AvailableBytes : DWORD;
ExtraBytes : DWORD;
ActualBytesRead : DWORD;
ExtraBytesRead : Integer;
pBuffer : PChar;
extBuffer : PChar;
Strm : TMemoryStream;
ch:string;
begin
try
ch:=request.QueryFields.Values['filename'];
TotalBytes := Request.ContentLength;
GetMem(pBuffer, TotalBytes);
pBuffer^ := Chr(0);
Strm := TMemoryStream.Create;
try
AvailableBytes := Length(Request.Content);
{ Put the contents of Request.Content into pBuffer }
pBuffer := PChar(Request.Content);
Strm.Write(pBuffer^,AvailableBytes);
{ Check to see if HTTP Content > Request.Content }
if TotalBytes > AvailableBytes then
begin
ExtraBytes := TotalBytes - AvailableBytes;
GetMem(extBuffer, ExtraBytes);
extBuffer^ := Chr(0);
ExtraBytesRead := 0;
repeat
ActualBytesRead := Request.ReadClient(extBuffer^,ExtraBytes - ExtraBytesRead);
Strm.Write(extBuffer^,ActualBytesRead);
Inc(ExtraBytesRead, ActualBytesRead);
until ExtraBytes - ExtraBytesRead = 0;
end; { Larger Than 48K }
strm.SaveToFile('d:/'+ch);
finally
Strm.Free;
end;
except
on E : Exception do
Response.Content := '文件上传失败!' + E.Message;
end;
end;
 
后退
顶部