Android Question Job.poststring problem

tufanv

Expert
Licensed User
Longtime User
Hello,

I need to post the data as json to an api with okhttp:
{"mode":"challenge","configuration":{"target":"ip","value":"1.2.3.4"},"notes":"This rule is on because of an event that occured on date X"}

I try this :
B4X:
    Dim text As String
    text=$"
    {"mode":"challenge","configuration":{"target":"ip","value":"7.7.7.7"},"notes":"This rule is on because of an event that occured on date X"}
    "$
    
    
    Dim job As HttpJob
    job.Initialize("block",Me)
    job.PostString("https:...",text)
    job.GetRequest.SetHeader("Content-Type","application/json")

but I always get : api.bad_json as result. If I post the same with postman or an api tester it works with sending this as raw body.

Am I doing stg Wrong ?
 

Peter Simpson

Expert
Licensed User
Longtime User
@tufanv do you need to set the header, how about just doing like below???

B4X:
    job.GetRequest.SetContentType("application/json")
 
Upvote 0
Top