'Post方法获取网页
'URL：字符串，目标域名或者IP地址+，目标页面的路径
'param：字符串，Post提交内容
'ref：字符串，引用页面
'user：字符串，用户名，如不需要则填空
'pwd：字符串，密码，如不需要则填空
'b= Http_Post( "http://www.yfvb.com/port.php","c=do&ID=99")
#Include Once "win/wininet.bi"

'--------------------------------------------------------------------------
Function Http_Post(ByVal URL as String, ByVal param as String, ByVal ref as String = "", ByVal user as String = "", ByVal pwd as String = "") as String
   Dim G_HTTP_Agent as ZString * MAX_PATH = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
   Dim G_HTTP_Head as ZString * 4096
   Dim G_HTTP_Accept as ZString * MAX_PATH = !"*/*"
   Dim G_HTTP_Ver as ZString * 32 = "HTTP/1.1"
   Dim G_HTTP_Block as UInteger = 4096
   Dim Prot As INTERNET_PORT
   Dim i As Long
   Dim G_HTTP_POST_HEAD as String = !"Content-Type: application/x-www-form-urlencoded\r\n"
   Dim sout as String, host as String, path as String
   URL_FenLiYuMinLuJing url, host, path, 0
   i = InStr(host, ":")
   If i > 0 Then  '指定了端口
      Prot = ValInt(Right(host, Len(host) - i))
      host = Left(host, i -1)
   Else
      Prot = INTERNET_DEFAULT_HTTP_PORT
   End If
   host &= Chr(0)
   path &= Chr(0)
   param &= Chr(0)
   ref &= Chr(0)
   user &= Chr(0)
   pwd &= Chr(0)
   DeleteUrlCacheEntry(StrPtr(URL))
   
   Dim hInet as HANDLE = InternetOpenA(@G_HTTP_Agent, INTERNET_OPEN_TYPE_DIRECT, Null, Null, 0)
   If hInet Then
      Dim hConn as HANDLE = InternetConnectA(hInet, StrPtr(host), Prot, StrPtr(user), StrPtr(pwd), INTERNET_SERVICE_HTTP, 0, 0)
      If hConn Then
         Dim hRequ as HANDLE = HttpOpenRequestA(hConn, "POST", StrPtr(path), @G_HTTP_Ver, StrPtr(ref), Cast(LPCSTR Ptr, @G_HTTP_Accept), INTERNET_FLAG_CACHE_IF_NET_FAIL, 0)
         If hRequ Then
            Dim bRequ as Integer = HttpSendRequestA(hRequ, G_HTTP_POST_HEAD & G_HTTP_Head, -1, StrPtr(param), Len(param) -1)
            If bRequ Then
               Dim tstr as String
               Dim bRead as UInteger
               tstr = String(G_HTTP_Block, 0)
               While InternetReadFile(hRequ, StrPtr(tstr), G_HTTP_Block, @bRead) AndAlso (bRead > 0)
                  sout &= Left(tstr, bRead)
               Wend
               InternetCloseHandle bRequ
            EndIf
            InternetCloseHandle hRequ
         EndIf
         InternetCloseHandle hConn
      EndIf
      InternetCloseHandle(hInet)
   EndIf
   Return sout
End Function