dimanche 22 août 2021

When sending an api from flutter web, if a complex format is entered in the body

{
    "title": 
        {
            "kr":"kr_title",
            "en":"en_title",
            "jp":"jp_title",
            "ch":"ch_title"
        }
    ,
    "content": 
        {
            "kr":"kr_content",
            "en":"en_content",
            "jp":"jp_content",
            "ch":"ch_content"
        }
}

The body have to contain these code. then i wrote below code in api's body. (kr_title, en_title, etc. are received as a parameter as a String.)

var response = await http.post(Uri.parse(url),
        headers: {
          "Content-Type":"application/x-www-form-urlencoded",
        },
        body: {
          "title": 
          {
            "kr": kr_title,
            "en": en_title,
            "jp": jp_title,
            "ch": ch_title
          }
          ,
          "content": 
          {
            "kr": kr_content,
            "en": en_content,
            "jp": jp_content,
            "ch": ch_content
          }
});

After that I found this error

Expected a value of type 'String', but got one of type 'IdentityMap<String, String>'

I'm not sure what to do in this situation. Shouldn't such a format be included in the body? please help😭😭😭😭😭




Aucun commentaire:

Enregistrer un commentaire