B4J Question jOKHTTPUtils2 Is Not Working

Ganiadi

Active Member
Licensed User
Longtime User
Dear All,

I Used below Http POST with JSON works fine in B4A, but when change to B4j it's not working for JSON, and it always threat like text and the result is in HTML format not in JSON like in B4A
Below is the code
HTTPPOST Request:
    Dim HTTPTask As HttpJob   
    HTTPTask.Initialize("HTTPTask", Me)
    HTTPTask.PostString("https://xxxxx", cJSONSTR)
    HTTPTask.GetRequest.SetContentType("application/json")
    wait for (HTTPTask) JobDone(HTTPTask As HttpJob)
    
    If HTTPTask.Success Then
        Json.Initialize(HTTPTask.GetString)
        Log(HTTPTask.GetString)
    End If
    HTTPTask.Release

Please help


Tks
 

Ganiadi

Active Member
Licensed User
Longtime User
This code is correct. The problem is somewhere else.

Hi Erel, Tks for your reply,

After trying and spent many times it's wotrking now by just adding HTTPTask.GetRequest.SetHeader("Accept","application/json")

B4X:
    Dim HTTPTask As HttpJob

    HTTPTask.Initialize("HTTPTask", Me)
    HTTPTask.PostString("https://xxxx", cJSONSTR)
    HTTPTask.GetRequest.SetContentType("application/json")
    HTTPTask.GetRequest.SetHeader("Accept","application/json")
    wait for (HTTPTask) JobDone(HTTPTask As HttpJob)
    
    If HTTPTask.Success Then
        Json.Initialize(HTTPTask.GetString)
        log(HTTPTask.GetString)

    End If
    HTTPTask.Release

Tks All
 
Upvote 0
Top