VBA以POST方式上传数据
时 间:2022-01-19 17:25:20
作 者:AngelHis ID:20576 城市:沈阳
摘 要:VBA以POST方式上传数据。
正 文:
'VBA以POST方式上传数据、
'--------------------------
'strUrl 网址
'strData 内容
'strHeader 头文件
'strValue 头文件格式
'===========================
Function f_uploadDataPost(intState As Integer, _
strUrl As String, _
Optional strData As String, _
Optional li_tdiff As Integer, _
Optional strHeader As String, _
Optional strValue As String) As String
On Error GoTo err
Dim http As Object
Dim I As Long
Dim lt_stime As Date, lt_ntime As Date
DoCmd.Hourglass True
Set http = CreateObject("Microsoft.XMLHTTP")
http.Open "POST", strUrl, False '同步抓取
If strHeader = "" Then strHeader = "CONTENT-TYPE"
If strValue = "" Then strValue = "application/x-www-form-urlencoded"
' Debug.Print strData
http.setRequestHeader strHeader, strValue '头文件
http.Send (strData) '
If li_tdiff = 0 Then li_tdiff = 10 '10秒
lt_stime = Now() '获取当前时间
While http.ReadyState <> 4
DoEvents
lt_ntime = Now '获取循环时间
If DateDiff("s", lt_stime, lt_ntime) > li_tdiff Then '服务器没有反应
DoCmd.Hourglass False
MsgBox "本机与【" & strUrl & "】通讯失败,服务器没有反应!", vbExclamation, "系统提示:" & http.Status
Set http = Nothing
Exit Function '判断超出li_tdiff秒即超时退出过程
End If
Wend
DoCmd.Hourglass False
I = http.Status
If I = 200 Then '定义字符串 json
f_uploadDataPost = http.responseText
If InStr(f_uploadDataPost, "Error_Code") > 0 Then
MsgBox f_uploadDataPost, , "系统提示"
f_uploadDataPost = ""
Else
Debug.Print "交易地址:" & strUrl & vbNewLine & vbNewLine & _
"输入json:" & strData & vbNewLine & vbNewLine & _
"输出json:" & f_uploadDataPost
End If
Else
intState = 100
MsgBox "本机与Json服务器通讯失败:" & Chr(13) & "Url【" & strUrl & "】" & Chr(13) & _
err.Description, vbExclamation, "系统提示 [f_uploadDataPost]" & "_" & http.Status
f_uploadDataPost = ""
End If
Set http = Nothing
Exit Function
err:
DoCmd.Hourglass False
intState = 100
MsgBox "与【" & strUrl & "】通讯失败:" & Chr(13) & _
Replace(Nz(err.Description, ""), "The system cannot locate the resource specified", "系统找不到指定的资源"), vbCritical, _
"系统提示 [f_uploadDataPost]" & intState
Set http = Nothing
End Function
Access软件网官方交流QQ群 (群号:312594938) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access源码示例】自定义...(05.25)
- 【Access Dcount函...(05.12)
- 【Access现学现用示例】主...(04.24)
- 【Access源码示例】获取本...(04.15)
- 【Access窗体查询示例】图...(04.07)
- 【Access条件格式示例】数...(04.01)
- 【Access IIF函数嵌套...(03.23)
- 【Access高效办公】Acc...(03.21)
- 【Access高效办公】Acc...(03.18)

学习心得
最新文章
- Office 更新导致:#已删除的...(05.28)
- 【Access自定义函数】确定两个...(05.28)
- 【Access Treeview树...(05.27)
- Access快速开发平台--自定义...(05.26)
- 《Access快速开发基础教程》免...(05.26)
- 【CNC数控编程参考工具】粗糙度切...(05.26)
- Access快速开发平台2.6.6...(05.25)
- 【Access源码示例】自定义通用...(05.25)
- 分享一套Office2019_PN...(05.25)
- Access2021官方下载,Ac...(05.24)