天天看點

vb發post資訊,非常簡單,就一個函數

如題

Function HttpPost(Url As String, PostMsg As String) As String

     '自己寫的發送Post的函數

     '函數傳回值是獲得的傳回資訊(HTML)

     '第一個參數是要發送的Url位址

     '第二個參數是要發送的消息(鍵值對應,不必編碼)

     Dim XmlHttp As Object

     Set XmlHttp = CreateObject("Msxml2.XMLHTTP")

     If Not IsObject(XmlHttp) Then

         Set XmlHttp = CreateObject("Microsoft.XMLHTTP")

         If Not IsObject(XmlHttp) Then Exit Function

     End If

     XmlHttp.Open "POST", Url, False

     XmlHttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"

     XmlHttp.Send EnUrl(PostMsg)

     Do While XmlHttp.readyState <> 4

         DoEvents

     Loop

     '如果把下面一行(以及後面的End IF)的注釋去除,即設定為僅當傳回碼是200時才傳回頁面内容

     'If XmlHttp.Status = 200 Then

         HttpPost = XmlHttp.responseText

     'End If

End Function

直接把這個函數放進窗體/子產品裡就行,不必引用任何東西

用法:

msgbox httppost("http://baidu.com","name1=value1&name2=value2")

(上面的位址和參數是瞎寫的)

-------------------

本人制作的非常非常垃圾的網站http://jybox.net