Home > Software design >  How to multipart post request this format in flutter?
How to multipart post request this format in flutter?

Time:06-27

var response = await http.post(Uri.parse(url),
      body: {
        "name": "name test",
        "about": about,
        "education[institute][0]": "ins one",
        "education[institute][1]": "ins two",
        "education[degree][0]": "deg one",
        "education[degree][1]": "deg two",
        "education[major][0]": "maj one",
        "education[major][1]": "maj two",
        "education[year][0]": "year one",
        "education[year][1]": "year two",
        "profession[position][0]": "pro one",
        "profession[position][1]": "pro two",
        "profession[company][0]": "com one",
        "profession[company][1]": "com two",
        "profession[start][0]": "star one",
        "profession[start][1]": "star two",
        "profession[end][0]": "end one",
        "profession[end][1]": "end two",
        "certification": certificate
      },
      headers: headers);

CodePudding user response:

You can try this way :

var uri = Uri.parse('url');
  var request = MultipartRequest('POST', uri);
  
  
  request.fields["name"] = "name test";
  request.fields["about"]= about;
  request.fields["education[institute][0]"]= "ins one";
  request.fields["education[institute][1]"]= "ins two";

  try {
      var streamedResponse = await request.send();
      var response = await Response.fromStream(streamedResponse);
      
      print(response.body);
    
      
    } catch (e) {
      rethrow;
    }
    

CodePudding user response:

I solved it after a long time. thank you

  • Related