Sub Process_Globals
Private hc As OkHttpClient
Private out As OutputStream
End Sub
Sub Service_Create
hc.Initialize("hc")
Send("https://www.b4x.com")
End Sub
Public Sub Send (URL As String)
Dim req As OkHttpRequest
Dim builder As JavaObject
builder.InitializeNewInstance("okhttp3.Request.Builder", Null)
builder.RunMethodJO("url", Array(URL)).RunMethod("method", Array("OPTIONS", Null))
Dim jo As JavaObject = req
jo.SetField("builder", builder)
hc.Execute(req, 0)
End Sub
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
Log("success")
Log(Response.GetHeaders) 'ignore
out.InitializeToBytesArray(0)
Response.GetAsynchronously("res", out, False, 0)
End Sub
Sub res_StreamFinish (Success As Boolean, TaskId As Int)
If Success Then
Dim b() As Byte = out.ToBytesArray
Log(BytesToString(b, 0, b.Length, "utf8"))
End If
End Sub
Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
Log("error")
End Sub