通过http访问的问题!

shawls 2002-05-04 03:35:08
通过http访问的问题!

如何通过http访问某个网页,得到网页的数据

但是:只使用api实现,怎么办?
...全文
34 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shawls 2002-05-17
  • 打赏
  • 举报
回复

copy from bardo,you can mail to shawfile@163.net
water_j 2002-05-04
  • 打赏
  • 举报
回复
to Shawls(小山(求职的程序员-谁让我发挥作用?))
你的API 声明是那里来的?
water_j 2002-05-04
  • 打赏
  • 举报
回复
to Shawls(小山(求职的程序员-谁让我发挥作用?))
你的API 声明是那里来的?
Chice_wxg 2002-05-04
  • 打赏
  • 举报
回复

祝贺祝贺!

shawls 2002-05-04
  • 打赏
  • 举报
回复
解决

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Private Const IF_FROM_CACHE = &H1000000
Private Const IF_MAKE_PERSISTENT = &H2000000
Private Const IF_NO_CACHE_WRITE = &H4000000

Private Const BUFFER_LEN = 256



Public Function GetUrlSource(sURL As String) As String
Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String
Dim hInternet As Long, hSession As Long, lReturn As Long

'get the handle of the current internet connection
hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
'get the handle of the url
If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
'if we have the handle, then start reading the web page
If hInternet Then
'get the first chunk & buffer it.
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sBuffer
'if there's more data then keep reading it into the buffer
Do While lReturn <> 0
iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
sData = sData + Mid(sBuffer, 1, lReturn)
Loop
End If
dengwei007 2002-05-04
  • 打赏
  • 举报
回复
同意楼上的,vb中最好用webbrowser控件
Chice_wxg 2002-05-04
  • 打赏
  • 举报
回复
Winsock系统,不适合在VB里使用。



或者 Internet*系列API
例如:
BOOL InternetReadFile(
IN HINTERNET hFile,
IN LPVOID lpBuffer,
IN DWORD dwNumberOfBytesToRead,
OUT LPDWORD lpNumberOfBytesRead
);
shawls 2002-05-04
  • 打赏
  • 举报
回复


大家帮忙!
water_j 2002-05-04
  • 打赏
  • 举报
回复
up!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧