I need to do some GETing and POSTing to a RESTful web service from VB6. What is the best and simplest way to do that?
我需要从VB6对RESTful Web服务进行一些GET和POST。最好和最简单的方法是什么?
3 个解决方案
#1
27
You'll need to add a reference to the MSXML library:
您需要添加对MSXML库的引用:
Dim sUrl As String
Dim response As String
Dim xmlhttp
Set sUrl = "http://my.domain.com/service/operation/param"
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", sURL, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send()
Dim response As String = xmlhttp.responseText
Set xmlhttp = Nothing
#2
12
I needed this for GET requests in an old legacy application recently, and since the accepted answer doesn't compile I thought I'd post some working code. I'm sure it will help some poor sole using VB6 in the future ;) Here's a nice clean function.
我最近在一个旧的遗留应用程序中需要这个GET请求,并且由于接受的答案没有编译,我想我会发布一些工作代码。我相信它将来会帮助一些使用VB6的可怜鞋底;)这是一个很好的清洁功能。
Public Function WebRequest(url As String) As String
Dim http As MSXML2.XMLHTTP
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.Open "GET", url, False
http.Send
WebRequest = http.responseText
Set http = Nothing
End Function
And here's example usage:
以下是示例用法:
Dim result As String
Dim url As String
url = "http://my.domain.com/service/operation/param"
result = WebRequest(url)
Happy VB6ing! :)
快乐的VB6ing! :)
#3
0
If you need to GET/POST from a REST Web service you can simply write an HTTP Request to the URL of the webservice:
如果需要从REST Web服务获取/ POST,您只需将HTTP请求写入Web服务的URL:
http://www.webservicehost.com/webserviceop?<any parameters>
If you need to pass complex objects you will need to serialize them and then pass them as parameters
如果需要传递复杂对象,则需要对它们进行序列化,然后将它们作为参数传递
You can then get the HTTP Response in whatever format the Web service decides to return as (JSON, XML, etc)
然后,您可以以Web服务决定返回的任何格式(JSON,XML等)获取HTTP响应
#1
27
You'll need to add a reference to the MSXML library:
您需要添加对MSXML库的引用:
Dim sUrl As String
Dim response As String
Dim xmlhttp
Set sUrl = "http://my.domain.com/service/operation/param"
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", sURL, False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send()
Dim response As String = xmlhttp.responseText
Set xmlhttp = Nothing
#2
12
I needed this for GET requests in an old legacy application recently, and since the accepted answer doesn't compile I thought I'd post some working code. I'm sure it will help some poor sole using VB6 in the future ;) Here's a nice clean function.
我最近在一个旧的遗留应用程序中需要这个GET请求,并且由于接受的答案没有编译,我想我会发布一些工作代码。我相信它将来会帮助一些使用VB6的可怜鞋底;)这是一个很好的清洁功能。
Public Function WebRequest(url As String) As String
Dim http As MSXML2.XMLHTTP
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.Open "GET", url, False
http.Send
WebRequest = http.responseText
Set http = Nothing
End Function
And here's example usage:
以下是示例用法:
Dim result As String
Dim url As String
url = "http://my.domain.com/service/operation/param"
result = WebRequest(url)
Happy VB6ing! :)
快乐的VB6ing! :)
#3
0
If you need to GET/POST from a REST Web service you can simply write an HTTP Request to the URL of the webservice:
如果需要从REST Web服务获取/ POST,您只需将HTTP请求写入Web服务的URL:
http://www.webservicehost.com/webserviceop?<any parameters>
If you need to pass complex objects you will need to serialize them and then pass them as parameters
如果需要传递复杂对象,则需要对它们进行序列化,然后将它们作为参数传递
You can then get the HTTP Response in whatever format the Web service decides to return as (JSON, XML, etc)
然后,您可以以Web服务决定返回的任何格式(JSON,XML等)获取HTTP响应