Android Question "message": "Request must have \"Content-Type: application/json\" header"

cesarcm

Member
Licensed User
Hi all,

Please, HELP ME!

I am getting the error below using job.PostString(link, data)

I am using B4A v8.00 and OkHttpUtils2 (v2.61)


ResponseError. Reason: UNSUPPORTED MEDIA TYPE, Response: {
"message": "Request must have \"Content-Type: application/json\" header"
}


Source-code:
...
Dim job As HttpJob
job.Initialize("", Me)
job.Download2(link, Array As String("Content-Type", "application/json"))
job.PostString(link, data)
...

Everything works fine for GET and DELETE !!!

Thanks.
Cesar
 

MarkusR

Well-Known Member
Licensed User
try this, data in this case contains a json string
B4X:
Job.PostString("http://www.abc/test" , data )
Job.GetRequest.SetContentType("application/json") 'need okhttp lib
 
Upvote 0

udg

Expert
Licensed User
job.Download2(link, Array As String("Content-Type", "application/json"))
This is a GET request to the server, so it's like you're sending a GET and a POST one after the other.

Follow @MarkusR advice to set the content type.
 
Upvote 0
Top