嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
无需任何OCX或DLL控件,直接调用windows内置对象实现HTTP请求,支持GET/POST等各种请求方法。返回HTML支持常见编码处理,避免中文乱码。
Dim Object As WinHttp.WinHttpRequest
If sUrl = "" Then Exit Function
If sMethod = "" Then sMethod = "GET"
'On Error Resume Next
Set Object = CreateObject("WinHttp.WinHttpRequest.5.1")
'非常重要(忽略SSL证书错误)
Object.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300
Object.SetTimeouts 6000, 15000, 60000, 60000 'DNS解析时间,连接时间,发数据时间,收数据时间
tmp = StrConv(sParam, vbUnicode)
Object.Open sMethod, sUrl, False '同步请求
Object.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.2840.71 Safari/537.36"
If sMethod = "POST" And InStr(tmp, "=") > 0 And InStr(tmp, "=") < 30 Then '有参数等号的情况才要设置Content-Type
Object.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
End If
Object.SetRequestHeader "Connection", "close"
Object.Send sParam
'httpRequest = Object.ResponseBody '字节数组一次性读取
httpRequest = Object.ResponseText '读取文本HTML,自动处理编码,部分网站会乱码
Set Object = Nothing