Help me send a POST request
I am using OkHttpUtils2 library with wait function
Here is the code for preparing the JSON request
Then I send it like this
And in response I receive an error message
(MyMap) {model=gpt-oss:120b-cloud, format=json, messages={role=user, content=привет}, think=true, stream=false, options={temperature=0.7, type=0.9}}
ResponseError. Reason: , Response: {"detail":[{"type":"json_invalid","loc":["body",0],"msg":"JSON decode error","input":{},"ctx":{"error":"Expecting value"}}]}
I can't figure out how to properly send a POST request with a payload in JSON format.
Help me
I am using OkHttpUtils2 library with wait function
Here is the code for preparing the JSON request
B4X:
Dim role As Map
role.Initialize
role.Put("role", "user")
role.Put("content", Mes)
Dim data As Map
data.Initialize
data.Put("model", model)
data.Put("format", "json")
data.Put("messages", role)
data.Put("think", True)
data.Put("stream", False)
Dim opt As Map
opt.Initialize
opt.Put("temperature", "0.7")
opt.Put("type","0.9")
data.Put("options", opt)
Then I send it like this
B4X:
Dim j As HttpJob
j.Initialize("", Me) 'name is empty as it is no longer needed
j.GetRequest.Timeout =5000 ' 5 seconds
j.PostMultipart(link,data, Null)
j.GetRequest.SetHeader("accept", "application/json")
j.GetRequest.SetContentType("application/json")
And in response I receive an error message
(MyMap) {model=gpt-oss:120b-cloud, format=json, messages={role=user, content=привет}, think=true, stream=false, options={temperature=0.7, type=0.9}}
ResponseError. Reason: , Response: {"detail":[{"type":"json_invalid","loc":["body",0],"msg":"JSON decode error","input":{},"ctx":{"error":"Expecting value"}}]}
I can't figure out how to properly send a POST request with a payload in JSON format.
Help me