I need to set Content-Type and Bearer Token with HTTP POST request. I searched the forum and failed to find any clear instruction. I tried to use **j.GetRequest.SetHeader("Content-Type","application/json")** which didn't work.
To post/put JSON-files I added following subroutines to HttpJob.Bas
B4X:
Public Sub PostJSON (Link As String, Text As String)
req.InitializePost2 (Link, Text.GetBytes ("UTF8"))
req.SetContentType ("application/json")
CallSubDelayed2 (HttpUtils2Service, "SubmitJob", Me)
End Sub
Public Sub PutJSONString (Link As String, Text As String)
PutBytes (Link, Text.GetBytes ("UTF8"))
req.SetContentType ("application/json")
End Sub
Request In activity (for POST):
B4X:
Dim httpjobInstance As HttpJob
httpjobInstance.Initialize ("", Me)
httpjobInstance.PostJSON (<http-address>, stringJSON)
httpjobInstance.GetRequest.SetHeader ("Authorization", "Bearer " & stringLoginAccessToken)