比如,我要判断 http://www.some.net/net.jpg 这个图片文件是否存在,怎么实现?
谢谢,在线等待

解决方案 »

  1.   

    分析下面的请求和应答包,你就知道如何解决了.一般地对于任何一个不存在的链接,远程的服务器都会返回一个404的状态码,你可以检查这个状态码来判断该文件是否存在.
    一般地发送http请求的各种方法中都包含了一获得status的方法.
    2003/10/18 15:26:6.485 (send,len=358) 
    GET /net.jpg HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*
    Accept-Language: zh-cn
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; MyIE2; .NET CLR 1.1.4322)
    Host: www.csdn.net
    Connection: Keep-Alive
    HTTP/1.1 404 Object Not Found
    Server: Microsoft-IIS/5.0
    Date: Sat, 18 Oct 2003 07:29:55 GMT
    Connection: close
    Content-Length: 4766
    Content-Type: text/html<!-- saved from url=(0022)http://internet.e-mail -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0066)http://expert.csdn.net/Expert/topic/1256/1256949.xml?temp=.1253626 -->
    <HTML dir=ltr><HEAD><TITLE>无法找到网页</TITLE>
    <STYLE>A:link {
    FONT: 9pt/11pt 宋体; COLOR: #ff0000
    }
    A:visited {
    FONT: 9pt/11pt 宋体; COLOR: #4e4e4e
    }
    </STYLE><META content=NOINDEX name=ROBOTS>
    <META http-equiv=Content-Type content="text-html; charset=gb2312">
    <META content=ZH-CN name=MS.LOCALE>
    <SCRIPT>
    function Homepage(){
    <!--
    // in real bits, urls get returned to our script like this:
    // res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm //For testing use DocURL = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"
    DocURL = document.URL; //this is where the http or https will be