Search code examples
androidflutterhttpdartflutter-android

how send put requests in flutter?


I am trying to update my json list on https://app.jsonstorage.net/

but i got response code 415 here is my code:

enter image description here

and this is my json on jsonstorage:

[{"username": "Amirhossein", "password": "302940101692", "email": "sahosseini1382@gmail.com", "phone": "09944236807"},{"username": "Hosna", "password": "74610945", "email": "hosseiniamir71@gmail.com", "phone": "09353792083"}]

Solution

  • 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"
            }
        )
    );