熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

非常有用的操作Internet的API函數

2013-11-23 19:07:53  來源: Java核心技術 

  必須安裝有Winnetdll文件 功能比WINSOCK強大 但MSDN裡的說明和例子都是C++的連VB的都沒有 我自己試探出這麼一些功能
  先貼出來供大家參考
  
  *所有函數如果運行失敗返回 成功返回或者句柄
  *參數大部分是用默認的參數具體內容查幫助文件
  
  檢查INTERNET是否連通
  DECLARE Integer InternetGetConnectedState IN wininetdll IntegerInteger
  InternetGetConnectedState()
  
  自動撥號使用默認的撥號連接 (IE的INTERNET連接設置裡必須設置撥號連接 另外還有個InternetDial函數必須使用撥號連接名稱)
  DECLARE Integer InternetAutodial IN wininetdll IntegerInteger
  InternetAutodial ()
  
  自動中斷撥號或者連接
  DECLARE Integer InternetAutodialHangup IN wininetdll Integer
  InternetAutodialHangup()
  
   獲得一個連接句柄
  Declare Integer InternetOpen IN wininetdll String Integer String String Integer
  lnOpen= internetOpen(MyFtpnullnull)
  
   連接到FTP SERVER
  Declare Integer InternetConnect in wininetdll IntegerStringIntegerString String Integer Integer Integer
  lnConn=InternetConnect(lnOpen anonymous )
  
   下載一個文件 還有不少FTP或者HTTP的操作文件或頁面的函數 有興趣者自己去試
  Declare Integer FtpGetFile in wininetdll Integer String String Integer IntegerIntegerInteger
  ? FtpGetFile(lnConn/bussys/readmetxtc:\Temp\msreadmetxt)
  
   中斷連接
  Declare Integer InternetCloseHandle In wininetdll Integer
  InternetCloseHandle(lnConn)
  
  下面是WININETDLL裡大部分的API函數是用VB格式的聲明:
  
  Declare Function GetProcessHeap Lib kernel () As Long
  Declare Function HeapAlloc Lib kernel (ByVal hHeap As Long ByVal dwFlags As Long ByVal dwBytes As Long) As Long
  Declare Function HeapFree Lib kernel (ByVal hHeap As Long ByVal dwFlags As Long lpMem As Any) As Long
  
  Declare Sub CopyMemory Lib kernel Alias RtlMoveMemory ( _
  hpvDest As Any ByVal hpvSource As Long ByVal cbCopy As Long)
  Declare Sub CopyMemory Lib kernel Alias RtlMoveMemory ( _
  hpvDest As Long hpvSource As Any ByVal cbCopy As Long)
  
  Public Const ERROR_NO_MORE_FILES =
  
  Public Declare Function InternetFindNextFile Lib wininetdll Alias InternetFindNextFileA _
  (ByVal hFind As Long lpvFindData As WIN_FIND_DATA) As Long
  
  Public Declare Function FtpFindFirstFile Lib wininetdll Alias FtpFindFirstFileA _
  (ByVal hFtpSession As Long ByVal lpszSearchFile As String _
  lpFindFileData As WIN_FIND_DATA ByVal dwFlags As Long ByVal dwContent As Long) As Long
  
  Public Declare Function FtpGetFile Lib wininetdll Alias FtpGetFileA _
  (ByVal hFtpSession As Long ByVal lpszRemoteFile As String _
  ByVal lpszNewFile As String ByVal fFailIfExists As Boolean ByVal dwFlagsAndAttributes As Long _
  ByVal dwFlags As Long ByVal dwContext As Long) As Boolean
  
  Public Declare Function FtpPutFile Lib wininetdll Alias FtpPutFileA _
  (ByVal hFtpSession As Long ByVal lpszLocalFile As String _
  ByVal lpszRemoteFile As String _
  ByVal dwFlags As Long ByVal dwContext As Long) As Boolean
  
  Public Declare Function FtpSetCurrentDirectory Lib wininetdll Alias FtpSetCurrentDirectoryA _
  (ByVal hFtpSession As Long ByVal lpszDirectory As String) As Boolean
  Public Declare Function FtpGetCurrentDirectory Lib wininetdll Alias FtpGetCurrentDirectoryA _
  (ByVal hFtpSession As Long ByVal lpszDirectory As String ByRef lpdwCurrentDirectory As Long) As Boolean
   Initializes an applications use of the Win Internet functions
  Public Declare Function InternetOpen Lib wininetdll Alias InternetOpenA _
  (ByVal sAgent As String ByVal lAccessType As Long ByVal sProxyName As String _
  ByVal sProxyBypass As String ByVal lFlags As Long) As Long
  
   Opens a HTTP session for a given site
  Public Declare Function InternetConnect Lib wininetdll Alias InternetConnectA _
  (ByVal hInternetSession As Long ByVal sServerName As String ByVal nServerPort As Integer _
  ByVal sUsername As String ByVal sPassword As String ByVal lService As Long _
  ByVal lFlags As Long ByVal lContext As Long) As Long
  
  Public Declare Function InternetGetLastResponseInfo Lib wininetdll Alias InternetGetLastResponseInfoA ( _
  lpdwError As Long _
  ByVal lpszBuffer As String _
  lpdwBufferLength As Long) As Boolean
  
   Type of service to access
  
   Opens an HTTP request handle
  Public Declare Function HttpOpenRequest Lib wininetdll Alias HttpOpenRequestA _
  (ByVal hHttpSession As Long ByVal sVerb As String ByVal sObjectName As String ByVal sVersion As String _
  ByVal sReferer As String ByVal something As Long ByVal lFlags As Long ByVal lContext As Long) As Long
  
   Sends the specified request to the HTTP server
  Public Declare Function HttpSendRequest Lib wininetdll Alias HttpSendRequestA (ByVal _
  hHttpRequest As Long ByVal sHeaders As String ByVal lHeadersLength As Long ByVal sOptional As _
  String ByVal lOptionalLength As Long) As Integer
  
  
   Queries for information about an HTTP request
  Public Declare Function HttpQueryInfo Lib wininetdll Alias HttpQueryInfoA _
  (ByVal hHttpRequest As Long ByVal lInfoLevel As Long ByRef sBuffer As Any _
  ByRef lBufferLength As Long ByRef lIndex As Long) As Integer
  
   InternetErrorDlg
  Public Declare Function InternetErrorDlg Lib wininetdll _
  (ByVal hWnd As Long ByVal hInternet As Long ByVal dwError As Long ByVal dwFlags As Long ByVal lppvData As Long) As Long
  
  Public Declare Function GetDesktopWindow Lib userdll () As Long
  
   The possible values for the lInfoLevel parameter include:
  
   Reads data from a handle opened by the HttpOpenRequest function
  Public Declare Function InternetReadFile Lib wininetdll _
  (ByVal hFile As Long ByVal sBuffer As String ByVal lNumBytesToRead As Long _
  lNumberOfBytesRead As Long) As Integer
  
  Public Declare Function HttpSendRequestEx Lib wininetdll Alias HttpSendRequestExA _
  (ByVal hHttpRequest As Long lpBuffersIn As INTERNET_BUFFERS ByVal lpBuffersOut As Long _
  ByVal dwFlags As Long ByVal dwContext As Long) As Long
  
  Public Declare Function HttpEndRequest Lib wininetdll Alias HttpEndRequestA _
  (ByVal hHttpRequest As Long ByVal lpBuffersOut As Long _
  ByVal dwFlags As Long ByVal dwContext As Long) As Long
  
  Public Declare Function InternetWriteFile Lib wininetdll _
  (ByVal hFile As Long ByVal sBuffer As String _
  ByVal lNumberOfBytesToRead As Long _
  lNumberOfBytesRead As Long) As Integer
  
  Public Declare Function FtpOpenFile Lib wininetdll Alias _
  FtpOpenFileA (ByVal hFtpSession As Long _
  ByVal sFileName As String ByVal lAccess As Long _
  ByVal lFlags As Long ByVal lContext As Long) As Long
  Public Declare Function FtpDeleteFile Lib wininetdll _
  Alias FtpDeleteFileA (ByVal hFtpSession As Long _
  ByVal lpszFileName As String) As Boolean
  
  Public Declare Function InternetSetOption Lib wininetdll Alias InternetSetOptionA _
  (ByVal hInternet As Long ByVal lOption As Long ByRef sBuffer As Any ByVal lBufferLength As Long) As Integer
  
  Public Declare Function InternetSetOptionStr Lib wininetdll Alias InternetSetOptionA _
  (ByVal
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26323.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.