使用 WinHttp 调用 RESTFul WebService
Invoking a RESTFul WebService using WinHttp
我对 VB6 和 REST 架构完全陌生。尽管如此,我还是想知道是否有 REST 客户端的任何 HelloWorld 示例,它使用 Windows HTTP 服务 API 调用 RESTFul webService。非常感谢。
解决方法如下:
Sub SendAsynchMessage()
Dim objHTTP As New WinHttp.WinHttpRequest
Dim doc As New MSXML2.DOMDocument
Dim root As MSXML2.IXMLDOMNode
Dim success As Boolean
Dim str As String
On Error GoTo ErrorHandler
success = doc.Load(App.Path & "\flow.xml")
Set root = doc.selectSingleNode("/root")
str = CStr(root.childNodes.Item(0).xml)
URL = "http://ipAddress:8081/messageAsynch"
objHTTP.Open "POST", url, False
objHTTP.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
objHTTP.Send (str)
Debug.Print objHTTP.Status
Debug.Print objHTTP.ResponseText
Exit Sub
ErrorHandler:
Dim E As ErrObject: Set E = Err
End Sub
"flow.xml" 文件在这种情况下可能如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<!-- your xml flow to be send via http -->
</root>
我对 VB6 和 REST 架构完全陌生。尽管如此,我还是想知道是否有 REST 客户端的任何 HelloWorld 示例,它使用 Windows HTTP 服务 API 调用 RESTFul webService。非常感谢。
解决方法如下:
Sub SendAsynchMessage()
Dim objHTTP As New WinHttp.WinHttpRequest
Dim doc As New MSXML2.DOMDocument
Dim root As MSXML2.IXMLDOMNode
Dim success As Boolean
Dim str As String
On Error GoTo ErrorHandler
success = doc.Load(App.Path & "\flow.xml")
Set root = doc.selectSingleNode("/root")
str = CStr(root.childNodes.Item(0).xml)
URL = "http://ipAddress:8081/messageAsynch"
objHTTP.Open "POST", url, False
objHTTP.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
objHTTP.Send (str)
Debug.Print objHTTP.Status
Debug.Print objHTTP.ResponseText
Exit Sub
ErrorHandler:
Dim E As ErrObject: Set E = Err
End Sub
"flow.xml" 文件在这种情况下可能如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<!-- your xml flow to be send via http -->
</root>