Delphi7 的IdHTTPServer 使用时出现的问题(100分)

  • 主题发起人 tihu1111
  • 开始时间
T

tihu1111

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在是用HTTPServer 来做一个下载服务器来供一个单片机来下载文件,
下面是对客户端发来请求的响应过程;
procedure TFrmMain.IdHTTPSCommandGet(AThread: TIdPeerThread;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
LocalDoc:string;
ByteSent: Cardinal;
dirstr:string;
begin
dirstr:=trim(G_httpDir);
LocalDoc:=ExpandFileName(dirstr+ARequestInfo.Document); //返回包含绝对路径
if not FileExists(LocalDoc)then
begin
ShowdataInfo(' HTTP |'+ARequestInfo.Command+' | '+ARequestInfo.RemoteIP+' | '+ARequestInfo.Document
+' 文件不存在');
exit;
end;
// uppercase(ARequestInfo.Command)='HEAD'
if AnsiSameText(ARequestInfo.Command, 'HEAD') then
begin
AResponseInfo.ContentLength := FileSizeByName(LocalDoc);
AResponseInfo.ContentText:=idhttps.MIMETable.GetFileMIMEType(LocalDoc);
ShowdataInfo(' HTTP |'+ARequestInfo.Command+'|'+ARequestInfo.RemoteIP+' | '+ARequestInfo.Document);
end
// uppercase(ARequestInfo.Command)='GET'
Else
begin
try
ByteSent:=IdHttpS.ServeFile(AThread,AResponseInfo,LocalDoc);
ShowdataInfo(' HTTP |'+ARequestInfo.Command+'|'+ARequestInfo.RemoteIP+'           |'+ARequestInfo.Document); //显示

except
On E:Exception do
begin
ShowdataInfo(' HTTP |'+ARequestInfo.Command+'|'+ARequestInfo.RemoteIP+'           |'+ARequestInfo.Document+' '+E.Message);
end;
end;

end
end;

问题:Socket Error # 0
  我用Idhttp 做客户端下载,是不会出现问题的。
  但是用 单片机来下载,有时就会报错 执行这个函数是 IdHttpS.ServeFile(AThread,AResponseInfo,LocalDoc);就是报错 Socket Error # 0; 
  报错时,IdHttpS.ServeFile(AThread,AResponseInfo,LocalDoc);函数,好久没有返回  另注:如果用在网上下载的一个http服务器 来做服务器,供单片机下载,却不会出现  这样的问题。
  请问:是不是我还有一些地方该设置的没有设置阿
    第一个用这个控件,也是第一个接触Http 请那位高手指教下!
   不胜感谢!  
 
没有人熟悉点IdHttpserver 的吗?
 
看来delphi 网络编程的程序员不多啊
 
你这个程序不应该写在 CommandGet 里面吧
应该写在执行里面吧。Socket Error # 0 可能是对方的Socket关闭了。
你还在尝试用这个套接字
 
仔细研究下http吧, http有1.0 ,1.1 看你的支持的哪个? 建议使用 WPE 1.0 抓包, 看是否有信息发出, 格式是否正确 ,该不会你的端口不正确吧? 对比网上下载的 http服务器响应格式和你自己写的, 如果能用下载的,何必自己写(本来就不熟悉)

是否打开了socket ?

是否给了下载文件名?
 
因为我要综合一个http下载服务器,和一个tcp 数据传输的服务器,
所以只有自己编写,

"是否打开了socket ?
是否给了下载文件名?"
这两个情况可以排除, 因为是下载某些文件时出现的情况!
而且,此时用IE来下载也是可以的.

"你这个程序不应该写在 CommandGet 里面吧
应该写在执行里面吧。Socket Error # 0 可能是对方的Socket关闭了。
你还在尝试用这个套接字"


----应该是写在这里的, 获得了客户端的请求命令,然后就给出相应的反应。


另外注,只有少数的文件下载时,会报这样的错误,如:bmp格式的图片
 
就你们两个回答了!但是都没有帮助我解决什么,但还是谢谢你们!
 
顶部