iOS Question send header and json to url

cloner7801

Active Member
Licensed User
Longtime User
You should post the solution so this thread can help others...
B4X:
    Dim datalist As List
        datalist.Initialize

        Dim data As Map
        data.Initialize
        data.put("JSONFIELD1", "VALUE1")
        data.put("JSONFIELD2", "VALUE2")
        datalist.add(data)
       
        Dim JSONGenerator As JSONGenerator
           JSONGenerator.Initialize2(datalist)
  
           Dim JSONstring As String
           JSONstring = JSONGenerator.ToString
           JSONstring = JSONstring.Replace("[","")
        JSONstring = JSONstring.Replace("]","")
       
        Dim bc As ByteConverter
         bc.StringToBytes(JSONstring,"utf-8")
    
         Dim hc As HttpClient
        Dim hr As HttpRequest
        hr.InitializePost2("URL",bc.StringToBytes(JSONstring,"utf-8"))
        hr.SetHeader("HEADER_NAME", "HEADER_VALUE")
        hr.SetHeader("Content-Type", "application/json")
        hr.SetContentType("application/json")

        hr.Timeout = 10000
        hc.Initialize("hc")
        hc.Execute(hr, 1)

B4X:
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Log("Success")
End Sub
Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
     Log("Error")
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…