惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
I
InfoQ
V
V2EX
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
G
Google Developers Blog
L
LangChain Blog
博客园_首页
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
月光博客
月光博客
IT之家
IT之家
量子位
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网

博客园 - 浪地

删除excel中重复的数据 - 浪地 - 博客园 SQL SERVER 与ACCESS、EXCEL的数据转换 水晶报表注册码 Request.ServerVariables的参数解析 - 浪地 - 博客园 Javascript中的函数替代ASP.NET的Server.UrlEncode C#实现的18位身份证格式验证算法(转) - 浪地 - 博客园 从SQL Server数据库提取图片并显示在DataGrid - 浪地 - 博客园 ASP.NET热点问题解答14个 把图片保存到sql server数据库里 JavaScript使用技巧精萃 - 浪地 - 博客园 T-SQL游标使用 SQL中通配符、转义符与"["号的使用 两台SQL Server数据同步解决方案 SQL Server中各个系统表的作用 SQL连接查询 SQL Server实用经验与技巧大汇集 SQLServer基本函数 ASP.NET中17种正则表达式(转) C#打包SQL数据库部署安装(原创啊)
从 HTTP 上下载文件示例
浪地 · 2006-12-29 · via 博客园 - 浪地

*直接运行下面 代码就可以了,在.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