标题:下载的网站有证书,请问这句URL_SESSION = INTERNETOPENURL(URL_OPEN,INTER ...
只看楼主
sych
Rank: 3Rank: 3
等 级:论坛游侠
威 望:6
帖 子:179
专家分:183
注 册:2019-10-11
结帖率:100%
已结贴  问题点数:20 回复次数:9 
下载的网站有证书,请问这句URL_SESSION = INTERNETOPENURL(URL_OPEN,INTER_URL,"",2,16,
cRemoteFile = "https://inv-veri.chinatax.
cLocalFile="增值税电子发票阅读器.zip"
URL_DOWNFILE(cRemoteFile,cLocalFile)
retu

FUNCTION URL_DOWNFILE
LPARAMETERS INTER_URL,LOCALFILE
DECLARE INTEGER InternetOpen IN wininet STRING, INTEGER, STRING, STRING, STRING
DECLARE INTEGER InternetOpenUrl IN wininet INTEGER, STRING, STRING, INTEGER, INTEGER, INTEGER
DECLARE INTEGER HttpQueryInfo IN wininet INTEGER, INTEGER, STRING @, INTEGER @, INTEGER @
DECLARE INTEGER InternetReadFile IN wininet INTEGER, STRING @, INTEGER, INTEGER @
DECLARE INTEGER InternetCloseHandle IN wininet INTEGER
URL_OPEN = INTERNETOPEN("qm3d",1,CHR(0),CHR(0),0)
IF URL_OPEN = 0
    RETURN -1
ENDIF
URL_SESSION = INTERNETOPENURL(URL_OPEN,INTER_URL,"",2,16,0)
IF URL_SESSION = 0
    = INTERNETCLOSEHANDLE(URL_OPEN)
    RETURN -2
ENDIF
URL_FOPEN = FCREATE(LOCALFILE)
IF URL_FOPEN = -1
    = INTERNETCLOSEHANDLE(URL_SESSION)
    = INTERNETCLOSEHANDLE(URL_OPEN)
    RETURN -3
ENDIF
URL_QUERYINFO = SPACE(32)
URL_QUERYINFOLEN = LEN(URL_QUERYINFO)
IF HTTPQUERYINFO(URL_SESSION,5,@URL_QUERYINFO,@URL_QUERYINFOLEN,0) = 1
    URL_FILESIZE = VAL(LEFT(URL_QUERYINFO,URL_QUERYINFOLEN))
ELSE
    URL_FILESIZE = -1
ENDIF
URL_SIZESUM = 0
URL_READBUFFER = REPLICATE(CHR(0),4096)
DO WHILE .T.
    URL_READBYE = 0
    IF INTERNETREADFILE(URL_SESSION,@URL_READBUFFER,4096,@URL_READBYE) = 1
        IF URL_READBYE = 0
            EXIT
        ELSE
            = FWRITE(URL_FOPEN,URL_READBUFFER,URL_READBYE)
        ENDIF
        URL_SIZESUM = URL_SIZESUM+URL_READBYE
        IF URL_FILESIZE = -1
            IF URL_SIZESUM > 0001048576
                WAIT WINDOW NOWAIT "正在下载 "+ALLTRIM(STR(URL_SIZESUM/0001048576,10,3))+"M……" AT sROWS()/2,SCOLS()/2-30
            ELSE
                WAIT WINDOW NOWAIT "正在下载 "+ALLTRIM(STR(URL_SIZESUM/1024))+"K……" AT sROWS()/2,SCOLS()/2-30
            ENDIF
        ELSE
            IF URL_SIZESUM > 0001048576
                WAIT WINDOW NOWAIT "正在下载 "+ALLTRIM(STR(URL_SIZESUM/0001048576,10,3))+"M "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
            ELSE
                WAIT WINDOW NOWAIT "正在下载 "+ALLTRIM(STR(URL_SIZESUM/1024))+"K "+STR(URL_SIZESUM/URL_FILESIZE*100,6,2)+"%……" AT sROWS()/2,SCOLS()/2-30
            ENDIF
        ENDIF
    ELSE
        EXIT
    ENDIF
ENDDO
WAIT CLEAR
= FCLOSE(URL_FOPEN)
= INTERNETCLOSEHANDLE(URL_SESSION)
= INTERNETCLOSEHANDLE(URL_OPEN)
RETURN URL_SIZESUM
ENDFUNC
搜索更多相关主题的帖子: INTEGER STRING IF wininet STR 
2021-04-25 14:13
sych
Rank: 3Rank: 3
等 级:论坛游侠
威 望:6
帖 子:179
专家分:183
注 册:2019-10-11
得分:0 
URL_SESSION = INTERNETOPENURL(URL_OPEN,INTER_URL,"",2,16,0)
这句出错不知道该如何修改?
2021-04-25 14:15
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
GetLastError 返回 12045,可能是是HTTPS请求证书错误
2021-04-25 19:39
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
以下是引用吹水佬在2021-4-25 19:39:12的发言:

GetLastError 返回 12045,可能是是HTTPS请求证书错误

2021-04-26 08:07
radiofan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:466
专家分:696
注 册:2006-7-30
得分:0 
myfll有个下载的函数:DownFile(cUrl[,cLocalFileName]),下不了这个链接 ……
2021-04-26 08:21
sych
Rank: 3Rank: 3
等 级:论坛游侠
威 望:6
帖 子:179
专家分:183
注 册:2019-10-11
得分:0 
就是证书的问题,但网上很多人也遇到过这个问题,也有解决方案,我试着改成vfp的,但都没有成功
2021-04-26 09:10
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用sych在2021-4-26 09:10:23的发言:

就是证书的问题,但网上很多人也遇到过这个问题,也有解决方案,我试着改成vfp的,但都没有成功

HTTPS是以安全为目标的HTTP协议,要身份验证。
证书的问题还与服务端有关,VFP的应用获得证书并安装应该就可以。
2021-04-26 20:24
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:20 
回复 6楼 sych
用winhttp库可以下载,测试环境:Windows 10 专业版 20H2,VFP9 SP2

程序代码:
CLEAR
SET TALK OFF
SET SAFETY OFF
CLEAR ALL
cDefPath = ADDBS(JUSTPATH(SYS(16)))
SET DEFAULT TO (cDefPath)

#define MAX_PATH    260

DECLARE LONG wcslen IN msvcrt LONG
DECLARE LONG strlen IN msvcrt STRING@

DECLARE LONG GetLastError   IN Kernel32
DECLARE LONG GetProcessHeap IN Kernel32
DECLARE LONG HeapAlloc      IN kernel32 LONG, LONG, LONG
DECLARE LONG HeapFree       IN Kernel32 LONG, LONG, LONG

DECLARE LONG WinHttpCrackUrl           IN winhttp LONG,LONG,LONG,STRING@
DECLARE LONG WinHttpOpen               IN winhttp STRING@,LONG,STRING@,LONG,LONG
DECLARE LONG WinHttpCloseHandle        IN winhttp LONG
DECLARE LONG WinHttpConnect            IN winhttp LONG,LONG,LONG,LONG 
DECLARE LONG WinHttpOpenRequest        IN winhttp LONG,STRING@,LONG,STRING@,STRING@,STRING@,LONG
DECLARE LONG WinHttpQueryOption        IN winhttp LONG,LONG,LONG@,LONG@ 
DECLARE LONG WinHttpSetOption          IN winhttp LONG,LONG,LONG@,LONG
DECLARE LONG WinHttpSendRequest        IN winhttp LONG,STRING@,LONG,STRING@,LONG,LONG,LONG
DECLARE LONG WinHttpReceiveResponse    IN winhttp LONG,LONG
DECLARE LONG WinHttpQueryHeaders       IN winhttp LONG,LONG,STRING@,STRING@,LONG@,LONG@
DECLARE LONG WinHttpQueryDataAvailable IN winhttp LONG,LONG@
DECLARE LONG WinHttpReadData           IN winhttp LONG,STRING@,LONG,LONG@


cUrl = "https://inv-veri.chinatax./download/ofd/增值税电子发票阅读器.zip"
cLocalFile = "增值税电子发票阅读器.zip"
_winhttpDownload(cUrl, cLocalFile)
RETURN

FUNCTION _HeapAlloc(nSize)
    RETURN HeapAlloc(GetProcessHeap(), 8, nSize)
ENDFUNC

FUNCTION _HeapFree(pBuffer)
    RETURN HeapFree(GetProcessHeap(), 1, pBuffer)
ENDFUNC

#defin _DEBUG
FUNCTION _ShowError(cText)
#ifdef _DEBUG
    MESSAGEBOX(cText + "  Error: " + TRANSFORM(GetLastError()))
#endif
ENDFUNC

FUNCTION _winhttpCrackUrl(pUrl, pScheme, pHostName, pUserName, pPassword, pUrlPath, pExtraInfo, nBufferSize)
    ucw = BINTOC(60,"4RS");
        + BINTOC(pScheme,"4RS")   + BINTOC(nBufferSize,"4RS") + BINTOC(0,"4RS");
        + BINTOC(pHostName,"4RS") + BINTOC(nBufferSize,"4RS") + BINTOC(0,"4RS");
        + BINTOC(pUserName,"4RS") + BINTOC(nBufferSize,"4RS");
        + BINTOC(pPassword,"4RS") + BINTOC(nBufferSize,"4RS");
        + BINTOC(pUrlPath,"4RS")  + BINTOC(nBufferSize,"4RS");
        + BINTOC(pExtraInfo,"4RS")+ BINTOC(nBufferSize,"4RS")
    nRet = WinHttpCrackUrl(pUrl, wcslen(pUrl), 0, @ucw)
    IF nRet==0
        _ShowError("WinHttpCrackUrl")
    ENDIF
    RETURN nRet != 0
ENDFUNC

FUNCTION _winhttpDownload(cUrl, cLocalFile)
    pUrl = _HeapAlloc(MAX_PATH)
    cUrl = STRCONV(cUrl+0h00, 5)
    SYS(2600, pUrl, LEN(cUrl), cUrl)
    
    pScheme    = _HeapAlloc(MAX_PATH)
    pHostName  = _HeapAlloc(MAX_PATH)
    pUserName  = _HeapAlloc(MAX_PATH)
    pPassword  = _HeapAlloc(MAX_PATH)
    pUrlPath   = _HeapAlloc(MAX_PATH)
    pExtraInfo = _HeapAlloc(MAX_PATH)
    
    IF !_winhttpCrackUrl(pUrl, pScheme, pHostName, pUserName, pPassword, pUrlPath, pExtraInfo, MAX_PATH)   
        _ShowError("_winhttpCrackUrl")
        RETURN .F.
    ENDIF

    hOpen = 0
    hConnect = 0
    hRequest = 0
    bResult = .F.
    
    FOR do_while=1 TO 1
        hOpen = WinHttpOpen(STRCONV("winhttpDownload"+0h00,5), 0, NULL, 0, 0)
        IF hOpen == 0
            _ShowError("WinHttpOpen")
            EXIT
        ENDIF
        
        hConnect = WinHttpConnect(hOpen, pHostName, 443, 0)
        IF hConnect == 0
            _ShowError("WinHttpConnect")
            EXIT
        ENDIF 
        
        hRequest = WinHttpOpenRequest(hConnect, STRCONV("GET"+0h00,5), pUrlPath, NULL, NULL, NULL, 0x800000)
        IF hRequest == 0
            _ShowError("WinHttpOpenRequest")
            EXIT
        ENDIF

        nFlags = 0
        nBuffLen = 4
        IF WinHttpQueryOption(hRequest, 0x1F, @nFlags, @nBuffLen) == 0
            _ShowError("WinHttpQueryOption")
            EXIT
        ENDIF
      
        nFlags = nFlags + 0x100 + 0x2000 + 0x1000
        IF WinHttpSetOption(hRequest, 0x1F, @nFlags, nBuffLen) == 0
            _ShowError("WinHttpSetOption")
            EXIT
        ENDIF

        IF WinHttpSendRequest(hRequest, NULL, 0, NULL, 0, 0, 0) == 0
            _ShowError("WinHttpSendRequest")
            EXIT
        ENDIF
        
        IF WinHttpReceiveResponse(hRequest, 0) == 0
            _ShowError("WinHttpReceiveResponse")
            EXIT
        ENDIF
        
        cContentLength = REPLICATE(STRCONV(0h00,5), 32)
        nCch = 64
        nHeaderIndex = 0
        nContentLength = 0
        IF WinHttpQueryHeaders(hRequest, 5, NULL, @cContentLength, @nCch, @nHeaderIndex) != 0
            nContentLength = INT(VAL(STRCONV(cContentLength,6)))
        ENDIF
        
        IF FILE(cLocalFile)
            DELETE FILE (cLocalFile)
        ENDIF
        fp = FCREATE(cLocalFile)
        IF fp < 0
            _ShowError("FOPEN")
            EXIT
        ENDIF

        nBufSize = 4096
        cBuffer = SPACE(nBufSize)
        nSize = 0
        nWrite = 0
        nOffset = 0
        ? "   download file: "+cLocalFile
        ?
        DO WHILE WinHttpQueryDataAvailable(hRequest,@nSize)!=0 AND nSize>0
            IF nSize > nBufSize
                nSize = nBufSize
            ENDIF
            WinHttpReadData(hRequest, @cBuffer, nSize, @nSize)
            FWRITE(fp, cBuffer, nSize)
            nOffset = nOffset + nSize
            ?? "  Downloading: "+TRANSFORM(nOffset)+"/"+TRANSFORM(nContentLength)+"(Byte)  "+TRANSFORM(INT(100*nOffset/nContentLength))+"%"+0h0D
        ENDDO
    
        FCLOSE(fp)
        bResult = .T.    
    ENDFOR
     
    IF hRequest != 0
        WinHttpCloseHandle(hRequest)
    ENDIF
    IF hConnect != 0
        WinHttpCloseHandle(hConnect)
    ENDIF 
    IF hOpen != 0
        WinHttpCloseHandle(hOpen)
    ENDIF
    
    _HeapFree(pUrl)
    _HeapFree(pScheme)
    _HeapFree(pHostName)
    _HeapFree(pUserName)
    _HeapFree(pPassword)
    _HeapFree(pUrlPath)
    _HeapFree(pExtraInfo)
    RETURN bResult
ENDFUNC

2021-04-30 00:59
schtg
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:https://t.me/pump_upp
等 级:贵宾
威 望:67
帖 子:1355
专家分:2534
注 册:2012-2-29
得分:0 
@吹版,学习啦,谢谢!
2021-04-30 05:50
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:0 
楼主惜字如金,金口玉言...................

坚守VFP最后的阵地
2021-05-01 15:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505571-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033091 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved