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

Discussion in 'Android Questions' started by cesarcm, Apr 13, 2018.

  1. cesarcm

    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
     
  2. MarkusR

    MarkusR Well-Known Member Licensed User

    try this, data in this case contains a json string
    Code:
    Job.PostString("http://www.abc/test" , data )
    Job.GetRequest.SetContentType(
    "application/json"'need okhttp lib
     
    jose luis gudino, Erel and DonManfred like this.
  3. udg

    udg Expert Licensed User

    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.
     
  4. cesarcm

    cesarcm Member Licensed User

    Markus!

    Thanks a lot!

    Now it works fine!

    Cesar
     
    MarkusR likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice