用VC++怎么判断某个url有效或者某个网址存在? 就是去用VC去得到某个网址的返回值比如:打开百度,可以访问,得到 http 200 打开某个不存在的网址,得到 400的错误 等等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 打开某个网址后, 获取http头部, 分析返回值 // Connect to www.baidu.com. HINTERNET hConnect = InternetConnect(hSession, "www.baidu.com", INTERNET_INVALID_PORT_NUMBER, "", "", INTERNET_SERVICE_HTTP, 0, 0); // Request the file /index.php from the server. HINTERNET hUrl = HttpOpenRequest(hConnect, "GET", "/index.php", HTTP_VERSION, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); // Add request headers TCHAR szHeaders[] = "Accept: text/*\r\n"; BOOL bAddHeaders = HttpAddRequestHeaders(hConnect, szHeaders, lstrlen(szHeaders), HTTP_ADDREQ_FLAG_ADD); // Send the request. BOOL bSendRequest = HttpSendRequest(hUrl, NULL, 0, 0, 0); if(hUrl == NULL) { printf("InternetOpenUrl Error......\n"); InternetCloseHandle(hSession); return 0; } BOOL bRet = HttpQueryInfo(hUrl, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwSizeOfStatusCode, NULL); if(!bRet) { printf("HttpQueryInfo Error......\n"); return 0; } // Key point if(404 == dwStatusCode) { InternetCloseHandle(hUrl) ; InternetCloseHandle(hSession) ; return 0; } 程序阻塞问题 FAR工具制作的 CHM 帮助文件 内部链接问题 关于滚动条刷新 DLL加载与卸载的问题! 哪位能Create一个XP风格的Edit框? InstallShield UNINSTALL的SCRIPT 求《windows核心编程》的源码 急急急:帮忙分析一下,谢谢各位大虾!!!!! 我想隐藏一个MDI的子窗口,该怎么办?谢谢!!! 感谢winphoenix给我做的程序 CreateFile 串口打不开,如下代码.....提示 打开COM失败 如何切换两块声卡?
// Connect to www.baidu.com.
HINTERNET hConnect = InternetConnect(hSession,
"www.baidu.com",
INTERNET_INVALID_PORT_NUMBER,
"",
"",
INTERNET_SERVICE_HTTP,
0,
0);
// Request the file /index.php from the server.
HINTERNET hUrl = HttpOpenRequest(hConnect,
"GET",
"/index.php",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0); // Add request headers
TCHAR szHeaders[] = "Accept: text/*\r\n";
BOOL bAddHeaders = HttpAddRequestHeaders(hConnect,
szHeaders,
lstrlen(szHeaders),
HTTP_ADDREQ_FLAG_ADD); // Send the request.
BOOL bSendRequest = HttpSendRequest(hUrl, NULL, 0, 0, 0); if(hUrl == NULL)
{
printf("InternetOpenUrl Error......\n");
InternetCloseHandle(hSession);
return 0;
}
BOOL bRet = HttpQueryInfo(hUrl, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwSizeOfStatusCode, NULL);
if(!bRet)
{
printf("HttpQueryInfo Error......\n");
return 0;
}
// Key point
if(404 == dwStatusCode)
{
InternetCloseHandle(hUrl) ;
InternetCloseHandle(hSession) ;
return 0;
}