zoukankan      html  css  js  c++  java
  • Windows CE 下判断 URL 地址是否有效

    直接上代码了。

     1 /* 
     2 有效网址:http://tyq3.huaxiazi.com/mp3/全人类最冷的27个笑话/lxh025.wma  
     3 无效网址:http://tyq3.huaxiazi.com/mp3/100001/奇幻鬼故事/qhggs00802.mp3  
     4 */  
     5 #include "Wininet.h"  
     6 #pragma comment (lib, "wininet.lib")   
     7 #define BUFFER_SIZE 20  
     8 BOOL CGetIPFromURLDlg::CheckUrlFileExist(TCHAR *ptcFileAddress)  
     9 {  
    10     HINTERNET hInternet = NULL;  
    11     TCHAR tcRet[BUFFER_SIZE + 1];  
    12     DWORD dwBufLength = BUFFER_SIZE;  
    13     DWORD dwIndex = 0;  
    14   
    15     ZeroMemory(tcRet,sizeof(TCHAR) * (BUFFER_SIZE + 1));  
    16   
    17     ghInstance = InternetOpen(L"InetURL:/1.0",   
    18         INTERNET_OPEN_TYPE_PRECONFIG,  
    19         NULL,  
    20         NULL,  
    21         0/*INTERNET_FLAG_ASYNC*/);  
    22     if(NULL == ghInstance)  
    23     {  
    24         RETAILMSG(1,(L"Call InternetOpen failed: %d
    ",GetLastError()));  
    25         return FALSE;  
    26     }  
    27     hInternet = InternetOpenUrl(ghInstance,ptcFileAddress,NULL,0,INTERNET_FLAG_RELOAD,0);  
    28     if(NULL == hInternet)  
    29     {  
    30         RETAILMSG(1,(L"Call InternetOpenUrl failed: %d
    ",GetLastError()));  
    31         return FALSE;  
    32     }  
    33     if(HttpQueryInfo(hInternet,HTTP_QUERY_STATUS_CODE,tcRet,&dwBufLength,&dwIndex))  
    34     {  
    35         if(0 != _wcsicmp(tcRet,L"200") && 0 != _wcsicmp(tcRet,L"302"))  
    36         {  
    37             RETAILMSG(1,(L"Invalid www address: %s!
    ",tcRet));  
    38             return FALSE;  
    39         }  
    40     }  
    41     else  
    42     {  
    43         RETAILMSG(1,(L"Call HttpQueryInfo failed: %d
    ",GetLastError()));  
    44         return FALSE;  
    45     }  
    46   
    47     RETAILMSG(1,(L"Valid www address: %s!
    ",tcRet));  
    48     return TRUE;  
    49 }  
  • 相关阅读:
    Mybatis-配置解析
    Mybatis-CRUD
    ExtJS3.4升级ExtJS4.2的问题汇总(转)
    Extjs视频
    Freemarker语法
    JSP 语法/标签
    android 入门-ID
    Win10 VS2015 社区版切换到VS2013社区版 进行维护之前的项目
    Win10 AppBar
    Win10 保存Element到相册
  • 原文地址:https://www.cnblogs.com/91program/p/5206244.html
Copyright © 2011-2022 走看看