Reputation: 76
I am trying to update my json list on https://app.jsonstorage.net/
but i got response code 415 here is my code:
and this is my json on jsonstorage:
[{"username": "Amirhossein", "password": "302940101692", "email": "[email protected]", "phone": "09944236807"},{"username": "Hosna", "password": "74610945", "email": "[email protected]", "phone": "09353792083"}]
Upvotes: 0
Views: 1448
Reputation: 1168
The code 415 means "Unsupported Media Type", and if you're getting that back it means you're successfully sending a put request to that URL, but with the wrong content type. Adding the following headers should resolve the issue:
Response resPut = await put(postUrl,
body: jsonEncode(<String, String>{
"username": username,
"password": password,
"email": email,
"phone": phone,
},
headers: {
"Accept": "application/json",
"content-type": "application/json",
},
));
If the error still occurs, I suggest that you read the documentation of the API you are consuming to see what you need to send.
Upvotes: 0
Reputation: 345
Try to add a header to your request:
Response resPut = await put (postur1,
body: jsonEncode(<String, String>{
"username": username,
"password": password,
"email": email,
"phone": phone
},
headers: {
"Accept": "application/json",
"content-type": "application/json"
}
)
);
Upvotes: 1