*直接運行下面 代碼就可以了,在.vfp8.0環境下測試成功! * How to download data of this reference (DBF files) using HTTP * 從 HTTP 上下載檔案 *------------------------------------------------------------------ Clea #Define INTERNET_OPEN_TYPE_DIRECT 1 #Define INTERNET_FLAG_NEED_FILE 16 #Define HTTP_QUERY_CONTENT_TYPE 1 #Define HTTP_QUERY_CONTENT_LENGTH 5 Do Decl && declare external functions *If InternetCheckConnection("http://www.163.com/", 1, 0) <> 0 &&已經串連Internet *Endif * initialize Wininet library Private hOpen hOpen = InternetOpen ("vfp", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0) If hOpen = 0 ? "GetLastError:", GetLastError() ? "在本機上 WinInet 函數庫無效" Return Endif Local lcBaseUrl, lcDstPath, hFile, lcFile lcBaseUrl = "http://ftpgz13.pconline.com.cn/pub/download/200203/Mp3RenameEasy.zip"&&根據實際修改這裡的字串 lcFile = "Mp3RenameEasy.zip"&&儲存的檔案名稱 lcDstPath = "C:\" &&儲存的路徑 * get a handle of the remote file hFile = InternetOpenUrl (hOpen,; lcBaseUrl , "", 0,; INTERNET_FLAG_NEED_FILE, 0) If hFile <> 0 ?hfile * even if there is no such file, the most evidently * you will get an ASCII file in response (404 error page) = http2local (hFile, lcDstPath + lcFile) = InternetCloseHandle (hFile) Else ? "網址不能開啟" ? "錯誤號碼:", GetLastError() Endif * release WinInet library = InternetCloseHandle (hOpen) Return && main *-------------------------------------------- Function http2local (hSource, lcTarget) * reads data from a remote file #Define TransferBuffer 4096 ? lcTarget + " " * create the target file hTarget = Fcreate (lcTarget) If (hTarget = -1) ?? "指定的目標檔案無效" Return -1 Endif Local Buffer , BufLen , dwIndex Buffer = Space(128) BufLen = Len(Buffer) dwIndex = 0 If HttpQueryInfo(hSource, HTTP_QUERY_CONTENT_LENGTH, @Buffer, @BufLen, @dwIndex) = 0 ?"擷取檔案資訊失敗!" Return -1 Endif ? ?"檔案大小: " + Left(Buffer,buflen)+" / " lnTotalBytesRead = 0 lnSec = Seconds() Do While .T. If Inkey() = 27 && 按 "Esc" 鍵 Exit Endif lcBuffer = Replicate(Chr(0), TransferBuffer) lnBytesRead = 0 If InternetReadFile (hSource, @lcBuffer,TransferBuffer, @lnBytesRead) = 1 = Fwrite (hTarget, lcBuffer, lnBytesRead) If lnBytesRead = 0 Exit Endif lnTotalBytesRead = lnTotalBytesRead + lnBytesRead Wait Window Transform(Val(Buffer)/1024) + " KB / " + Transform(lnTotalBytesRead/1024) + " KB " Nowait Else Exit Endif DoEvents Enddo = Fclose (hTarget) ?? " " + Transform(lnTotalBytesRead) + " Bytes 完成 用時: " + Transform(Seconds() - lnSec) + " 秒" Return lnBytesRead Endfunc Procedure Decl Declare Integer InternetCheckConnection In wininet.Dll ; String lpszUrl ,; Integer dwFlags ,; Integer dwReserved Declare Integer GetLastError In kernel32 Declare Integer InternetOpen In wininet; STRING sAgent,; INTEGER lAccessTypem,; STRING sProxyName,; STRING sProxyBypass,; STRING lFlags Declare Integer InternetCloseHandle In wininet Integer hInet Declare Integer InternetOpenUrl In wininet; INTEGER hInternet,; STRING lpszUrl,; STRING lpszHeaders,; INTEGER dwHeadersLength,; INTEGER dwFlags,; INTEGER dwContext Declare Integer InternetReadFile In wininet; INTEGER hFile,; STRING @ lpBuffer,; INTEGER dwNumberOfBytesToRead,; INTEGER @ lpdwNumberOfBytesRead Declare Integer HttpQueryInfo In wininet ; INTEGER hHttpRequest, ; INTEGER lInfoLe |