CodePudding user response:
Online, etc.,,,,CodePudding user response:
http://www.json.orgBaidu search "VBA HTTP POST"
CodePudding user response:
Commonly used method is to use Microsoft. XMLHTTP components, the following is wrapped a function,PostData:
Parameters:
StrUrl -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- accept submitted URL
StrData -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- need to submit the data, such as JSON string, a string or login user=xxx&" PSW=XXX
"VarAsyncX -- -- -- -- -- -- -- -- -- -- -- -- -- -- set working mode for synchronous or asynchronous, true (asynchronous) or false (synchronous), usually using asynchronous way,
CodePageX -- -- -- -- -- -- -- -- -- -- -- -- the return data decoding, encoding, string: GB2312 or utf-8
'==================================================
The Public Function PostData (ByVal StrUrl As String, ByVal StrData As String, varAsyncX As a Boolean, CodePageX As String) As the Variant
'On Error GoTo ERR:' ByVal DataStic As DataEnum,
Dim XMLHTTP As Object, GetBody
Dim DataS As String
Dim DataB () As Byte
The Set XMLHTTP=CreateObject (" Microsoft. XMLHTTP ")
XMLHTTP. Open the "POST", StrUrl, varAsyncX 'True
'XMLHTTP. SetRequestHeader "Content - Length", Len (PostData)
XMLHTTP. SetRequestHeader content-type ", "" application/x - WWW - form - urlencoded"
XMLHTTP. Send (StrData)
If varAsyncX Then
Do Until XMLHTTP. ReadyState=4
DoEvents
Loop
End the If
GetBody=XMLHTTP. ResponseBody
If Len (GetBody) & gt; 1 Then
GetBody=BytesToStr (GetBody CodePageX)
PostData=https://bbs.csdn.net/topics/GetBody
End the If
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
release spaceExitX:
The Set XMLHTTP=Nothing
The Exit Function
ERR:
PostDatahttps://bbs.csdn.net/topics/=""
Resume exitX 'Next
End the Function
Public Function BytesToStr (strBody CodeBase)
Dim objStream
The Set objStream=CreateObject (" Adodb. Stream ")
With objStream
. Type=1
. Mode=3
. Open
The.write strBody
. The Position=0
Type=2
The Charset=CodeBase '" GB2312 "'
BytesToStr=. ReadText
. Close
End With
The Set objStream=Nothing
End the Function