如何判断网络上一个文件是否存在?

jimware 2003-10-18 10:29:44
比如,我要判断 http://www.some.net/net.jpg 这个图片文件是否存在,怎么实现?
谢谢,在线等待
...全文
36 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
microran2000 2003-10-18
  • 打赏
  • 举报
回复
分析下面的请求和应答包,你就知道如何解决了.一般地对于任何一个不存在的链接,远程的服务器都会返回一个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

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧