您的位置:程序门 -> delphi -> 网络通信/分布式开发



如何判断这中   url     http://www.baidu.com/baidu.rar     是不是有效   


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何判断这中 url http://www.baidu.com/baidu.rar 是不是有效
发表于:2008-01-10 12:04:28 楼主
如何判断这中       url           http://www.baidu.com/baidu.rar           是不是有效      
下面这个函数       是我写的           如果参数是           http://www.baidu.com       这个函数有效       但是参数是http://www.baidu.com/baidu.rar的时候这个函数       就没了效果谁能告诉我应该怎么改          
function       get(url:       string):       boolean;  
    var  
        idhttp:       tidhttp;  
        ss:       string;  
    begin  
        result:=       false;  
        idhttp:=       tidhttp.create(nil);  
        try  
                try  
                            idhttp.handleredirects:=       true;               //必须支持重定向否则可能出错9c       ?$m       g7z       y       {0k       m       o  
                        idhttp.readtimeout:=       30000;                           //超过这个时间则不再访问  
                            ss:=       idhttp.get(url);  
                            if       idhttp.responsecode=200       then  
                                result       :=true;  
                except  
                end;  
        finally  
                idhttp.free;  
        end;  
    end;  
   
function       get(url:       string):       boolean;  
    var  
        idhttp:       tidhttp;  
        ss:       string;  
    begin  
        result:=       false;  
        idhttp:=       tidhttp.create(nil);  
        try  
                try  
                            idhttp.handleredirects:=       true;               //必须支持重定向否则可能出错9c       ?$m       g7z       y       {0k       m       o  
                        idhttp.readtimeout:=       30000;                           //超过这个时间则不再访问  
                            ss:=       idhttp.get(url);  
                            if       idhttp.responsecode=200       then  
                                result       :=true;  
                except  
                end;  
        finally  
                idhttp.free;  
        end;  
    end;
发表于:2008-01-10 17:09:421楼 得分:0
直接获取你最后要得到的数据,看字节数,如果返回是大于0的字节数,就证明是有的
发表于:2008-01-11 15:35:522楼 得分:0
在第一个try   的except   里面   进行处理     看报的是http       404   ,http     302,这样的   ~再根据错的不同的信息进行处理
\
发表于:2008-01-11 15:45:403楼 得分:0
试试楼主的代码,都能正常返回,但是得到的都是百度给出的出错页面


快速检索

最新资讯
热门点击