-
-
Save wqweto/8ccac82377baf5e6e362da27647cb029 to your computer and use it in GitHub Desktop.
'========================================================================= | |
' | |
' First add mdJson.bas module to your project from this address | |
' | |
' https://gist.github.com/wqweto/e92dce63a68cd3ff9ca91b053b9510c9 | |
' | |
' Then copy/paste follwing code into an empty form | |
' | |
' Change STR_URL and STR_APIKEY to match your API address and credentials | |
' | |
'========================================================================= | |
Option Explicit | |
Private Sub Form_Load() | |
Const STR_URL As String = "http://127.0.0.1:61345/" | |
Const STR_APIKEY As String = "123456" | |
Dim oJson As Object | |
Dim oMessage As Object | |
JsonValue(oMessage, "$.text") = "test msg 88" | |
JsonValue(oMessage, "$.numbers[-1]") = "966555528643" | |
JsonValue(oMessage, "$.numbers[-1]") = "966555528644" | |
JsonValue(oMessage, "$.numbers[-1]") = "966555528645" | |
JsonValue(oMessage, "$.number_iso") = "SA" | |
JsonValue(oMessage, "$.sender") = "" | |
JsonValue(oJson, "$.messages[-1]") = oMessage | |
' Debug.Print JsonDump(oJson) | |
Dim oResponse As Object | |
Dim sError As String | |
Set oResponse = JsonParseObject(pvPostJson(STR_URL, STR_APIKEY, JsonDump(oJson)), sError) | |
If oResponse Is Nothing Then | |
Debug.Print sError | |
End If | |
End Sub | |
Private Function pvPostJson(sUrl As String, sApiKey As String, sPostData As String) As String | |
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER As Long = 0 | |
With CreateObject("WinHttp.WinHttpRequest.5.1") | |
.Open "POST", sUrl | |
.SetRequestHeader "Accept", "application/json" | |
.SetRequestHeader "Content-Type", "application/json" | |
.SetRequestHeader "User-Agent", "Etqan" | |
.SetCredentials sApiKey, vbNullString, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER | |
.Send sPostData | |
pvPostJson = .ResponseText | |
End With | |
End Function |
You'll need mdJson.bas
module added to your project first. Then just copy/paste the sample code in the default form called Form1
.
Here is a complete VB6 project zipped with Form1
sample code pasted and mdJson
module included: JsonAPI.zip
You have to change these two constants
Const STR_URL As String = "https://some.url.here/"
Const STR_APIKEY As String = "some-key-here"
thank you dear
I did that but no succeed because I thank must me I put API Secret
you don't put API Secret in the code
must me I put url , Api key and Api secret
Mail me complete working code with complete working JSON request, real API service address and your real API secret in any language you already have (PHP, C#, whatever) and I'll send you back a working VB6 code for you to study.
You can find my e-mail address in my github profile or in header of shared code I have on the internet.
thank you but Not working , maybe must me I put code API Secret ... Where I put it?