Public Sub TestRestAPI() As ResumableSub
Dim Result As String
Dim sURL As String = "---- URL API REST ----"
Dim sBodyParameters As String = "---- BODY -----"
Dim sApiKey As String = "---- API KEY ----"
Dim j As HttpJob
Try
j.Initialize("", Me)
j.PostString(sURL, sBodyParameters)
j.GetRequest.SetHeader("x-api-key", sApiKey)
j.GetRequest.SetHeader("Content-Type", "application/json")
SetRequestTimeOut(3000, 3000, 65000)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Result = j.GetString
Else
Result = j.ErrorMessage
End If
Catch
Log(LastException)
End Try
j.Release
Return Result
End Sub
Public Sub SetRequestTimeOut(ConnectTime As Long, CallTime As Long, ReadTime As Long)
Dim jo As JavaObject = HttpUtils2Service.hc
Dim builder As JavaObject = jo.RunMethod("sharedInit", Array("hc"))
Dim TimeUnit As JavaObject
TimeUnit.InitializeStatic("java.util.concurrent.TimeUnit")
builder.RunMethod("connectTimeout", Array(ConnectTime, TimeUnit.GetField("MILLISECONDS")))
builder.RunMethod("callTimeout", Array(CallTime, TimeUnit.GetField("MILLISECONDS")))
builder.RunMethod("readTimeout", Array(ReadTime, TimeUnit.GetField("MILLISECONDS")))
jo.SetField("client", builder.RunMethod("build", Null))
End Sub