</pre><pre name="code" class="vb">'作用:winHttp的post或者get
'参数:postURL,post或get网址
'参数:postData,post内容
'参数:Method,方法,为"POST"或"GET"
'参数:setCookies,post或get带上的cookie
'返回:post或get返回的内容
Public Function winHttpGetResponse(postURL As String, postData As String, Method As String, setCookies As String) As String
If Len(Trim(setCookies)) = 0 Then setCookies = "a:x," '//cookie为空则随便弄个cookie,不然报错
Set WinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") '创建WinHttp.WinHttpRequest
'MsgBox "到 这里"
WinHttp.Open Method, postURL, True '同步接收数据
WinHttp.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300 '非常重要(忽略错误)
'其它请求头设置
WinHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttp.SetRequestHeader "Cookie", setCookies
WinHttp.SetRequestHeader "Content-Length", Len(postData)
WinHttp.Send postData '' 开始发送
WinHttp.WaitForResponse '等待请求
'MsgBox WinHttp.Status'请求状态
'得到返回文本(或者是其它)
winHttpGetResponse = WinHttp.ResponseText
End Function
vb6.0 winHttp的post或get一个函数
最新推荐文章于 2024-09-24 13:37:14 发布