VB6 调用HttpsAPI请求(WinHttp.WinHttpRequest)

这篇博客介绍了如何在VB6客户端中通过WinHttp组件的WinHttpRequest对象访问HTTPS API。首先需要引用Microsoft WinHTTP Services组件,然后设置SSL错误忽略标志,使用WinHttpRequest对象进行同步POST请求,并设置请求头。最后,发送数据并获取响应,从而实现HTTPS API的调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VB6客户端中如何访问Https的API请求呢?

使用WinHttp组件里的WinHttpRequest对象可以解决我们的问题。
1、引用“Microsoft WinHTTP Services, version 5.1”组件
2、下面是源代码 

Public Function HttpsRequest(ByVal strIn As String,ByVal url As String ,ByRef strOut As String) As Boolean
    On Error GoTo 0   ' 关闭错误陷阱。
    On Error GoTo errexit
    'Dim oXmlhttp As MSXML2.XMLHTTP
    'Set oXmlhttp = New MSXML2.XMLHTTP
    'Dim oXmlhttp As MSXML2.ServerXMLHTTP
    'Set oXmlhttp = New MSXML2.ServerXMLHTTP
    'https 地址的使用下面的请求方式;XMLHTTP提示指定资源下载失败则使用ServerXMLHTTP;
    '使用ServerXMLHTTP提示证书中主名称无效则使用下面方式请求
    
    Dim oXmlhttp As WinHttp.WinHttpRequest 

    ''创建WinHttp.WinHttpRequest
    Set oXmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")

    '' 忽略调用错误
    oXmlhttp.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = &H3300

    '同步接收数据
    oXmlhttp.Open "post", url, False

    '其它请求头设置
    oXmlhttp.setRequestHeader "accept-encoding", "gzip,deflate"
    oXmlhttp.setRequestHeader "content-type", "application/x-www-form-urlencoded;charset=UTF-8"
    
    '发送数据请求
    oXmlhttp.send strIn

    '得到返回数据,这里根据情况确定
    strOut = oXmlhttp.responseText
    HttpsRequest= True

    Set oXmlhttp = Nothing
    Exit Function
errexit:
    Set oXmlhttp = Nothing
    MsgBox "调用失败:" & Err.Description, vbInformation + vbOKOnly, "瀚文软件"
    Err.Clear
    HttpsRequest = False
End Function

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

長安旧夢

知识的大门打开后,才有真正机会

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值