Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get/post to RESTful web service

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?

like image 696
Echo says Reinstate Monica Avatar asked Aug 18 '10 19:08

Echo says Reinstate Monica


People also ask

Can RESTful web services use HTTP POST method?

POST is the only RESTful API HTTP method that primarily operates on resource collections. When creating a subordinate resource in a collection, applying POST to the parent resource prompts it to create a new resource, associate it with the proper hierarchy and return a dedicated URL for later reference.

Does REST API use Get or POST?

GET requests should be used to retrieve data when designing REST APIs; POST requests should be used to create data when designing REST APIs. Creating something is a side effect — if not the point. The HTTP GET method isn't supposed to have side effects. It's considered read-only for retrieving data.

How do you create a request and send it to the REST web service?

To make a RESTful web service request, you need the following: URL - The URL that hosts the RESTful web service. Method - The type of HTTP method to use for sending the request, for example GET , PUT , POST , or DELETE . Request header - The attributes that describe the request.


2 Answers

You'll need to add a reference to the MSXML library:

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 
like image 104
Justin Niessner Avatar answered Sep 21 '22 03:09

Justin Niessner


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.

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! :)

like image 29
craftworkgames Avatar answered Sep 22 '22 03:09

craftworkgames