Flutter - Send Json over HTTP Post

后端 未结 3 2007
攒了一身酷
攒了一身酷 2021-01-12 23:39

I am trying to send a Json over HTTP post to update a record in my database. I\'ve connected to the server but I\'m getting a 415 \"Unsupported Media Type\" error when I run

3条回答
  •  忘掉有多难
    2021-01-13 00:01

    You'll have to add the content-type to your header, setting its value to application/json.

    By specifying Accept you're saying that your client is able to understand that response type, not that your request content is of the JSON type.

    Basically you're saying "hey there, I'm able to understand JSON, so you can send it to me and I'll be fine with it" but you're not saying "hey I'm going to send you a JSON, be prepared for it!"

    For a better understanding, you can find more about Accept here and Content-type here.

提交回复
热议问题