API Call Using Visual Basic 6 (JSON Response)
Today. I’m gonna show you how to make API (Application Programming Interface) Call using Microsoft Visual Basic 6. And the first step that you have to do is install Visual Basic, I’m using Visual Basic 6 by the way.
First, you must create Visual Basic Project and then go to Project – References , Add Microsoft XML v6.0 and then click OK.
Make a Procedure let say GetRequest
Public Sub GetRequest
Dim xmlhttp As New MSXML2.XMLHTTP60
Dim url as String
Dim Response as String
‘set url
url = https://api.yourwebsite.com
xmlhttp.Open “POST”, url, False
‘set header
xmlhttp.setRequestHeader "Host:", "api.your.api.url.destionation.com"
xmlhttp.setRequestHeader " Key:", "xyz"
xmlhttp.setRequestHeader " Token:", "$2a$10$ "
xmlhttp.setRequestHeader "Origin:", "http://web.com"
xmlhttp.setRequestHeader "Content-Type", "application/json"
‘set body
sEntityBody = "{" + vbCrLf + """reference_id"":999," + vbCrLf
sEntityBody = sEntityBody & """image""" & ":" & Base64StringImage & vbCrLf & "}"
xmlhttp.send " " + sEntityBody
‘if status 200 ( success )
If xmlhttp.status = "200" Then
Response = xmlhttp.responseText
Set xmlhttp = Nothing
When we receive a response from server than we must parse JSON with JSON Parser
Set p = JSON.parse(Response)
JSON parser for Visual Basic you can download from here and add to Project Modules.
If we want to extract data from JSON we can user object pointer like below :
Text1.text = P.item(“data” .Item("province").Item("raw")
If we want to extract data from members of the item we can code like this below :
For I = 1 To p.Item("data").Item("member").Count()
p.Item("data").Item("member")(I).Item("name")
Next I
End if
Hope this article help you.
Download Source Code API Call VB 6 here
Software :
Operating System :
Labels: API, JSON, Visual Basic
0 Comments:
Post a Comment
<< Home