How make a http post using form data in flutter?

Use Map instead, because body in http package only has 3 types: String, List<int> or Map<String, String>. Try this: final Uri uri = Uri.parse(‘https://na57.salesforce.com/services/oauth2/token’); final map = <String, dynamic>{}; map[‘grant_type’] = ‘password’; map[‘client_id’] = ‘3MVG9dZJodJWITSviqdj3EnW.LrZ81MbuGBqgIxxxdD6u7Mru2NOEs8bHFoFyNw_nVKPhlF2EzDbNYI0rphQL’; map[‘client_secret’] = ’42E131F37E4E05313646E1ED1D3788D76192EBECA7486D15BDDB8408B9726B42′; map[‘username’] = ‘[email protected]’; map[‘password’] = ‘ABC1234563Af88jesKxPLVirJRW8wXvj3D’; http.Response response = await http.post( uri, body: map, );

Upload a base64 encoded image using FormData?

var imgBase64 = “data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCA…” //your bse64 image onSubmit(){ const file = DataURIToBlob(imgBase64) const formData = new FormData(); formData.append(‘upload’, file, ‘image.jpg’) formData.append(‘profile_id’, this.profile_id) //other param formData.append(‘path’, ‘temp/’) //other param } function DataURIToBlob(dataURI: string) { const splitDataURI = dataURI.split(‘,’) const byteString = splitDataURI[0].indexOf(‘base64’) >= 0 ? atob(splitDataURI[1]) : decodeURI(splitDataURI[1]) const mimeString = splitDataURI[0].split(‘:’)[1].split(‘;’)[0] const ia = new … Read more

Testing Form posts through MockMVC

If you have Apache HTTPComponents HttpClient on your classpath, you can do it like this: mockMvc.perform(post(“/some/super/secret/url”) .contentType(MediaType.APPLICATION_FORM_URLENCODED) .content(EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList( new BasicNameValuePair(“someparam1”, “true”), new BasicNameValuePair(“someparam2”, “test”) ))))); If you don’t have HttpClient, you can do it with a simple helper method that constructs the urlencoded form entity: mockMvc.perform(post(“/some/super/secret/url”) .contentType(MediaType.APPLICATION_FORM_URLENCODED) .content(buildUrlEncodedFormEntity( “someparam1”, “value1”, “someparam2”, “value2” )))); With … Read more

How to set File objects and length property at FileList object where the files are also reflected at FormData object?

Edit: As proven by OP, in one of their gist, there is actually a way to do it… The DataTransfer constructor (currently only supported by Blink, and FF >= 62), should create a mutable FileList (chrome currently always return a new FileList, but it doesn’t really matter for us), accessible through the DataTransferItemList. If I’m … Read more

FormData append nested object

let formData = new FormData(); let data = { title: ‘title’, text: ‘text’, preview: {p_title:’p title’, p_text: ‘p text’} }; for(let dataKey in data) { if(dataKey === ‘preview’) { // append nested object for (let previewKey in data[dataKey]) { formData.append(`preview[${previewKey}]`, data[dataKey][previewKey]); } } else { formData.append(dataKey, data[dataKey]); } } Console formData for (let val of … Read more

Send FormData and String Data Together Through JQuery AJAX?

var fd = new FormData(); var file_data = $(‘input[type=”file”]’)[0].files; // for multiple files for(var i = 0;i<file_data.length;i++){ fd.append(“file_”+i, file_data[i]); } var other_data = $(‘form’).serializeArray(); $.each(other_data,function(key,input){ fd.append(input.name,input.value); }); $.ajax({ url: ‘test.php’, data: fd, contentType: false, processData: false, type: ‘POST’, success: function(data){ console.log(data); } }); Added a for loop and changed .serialize() to .serializeArray() for object reference … Read more

How to get a key/value data set from a HTML form

When I originally wrote this answer FormData was not widely supported (and this was called out explicitly in the question). Now that it’s been 6 years, FormData has excellent cross-browser support. Because of this, I highly recommend using FormData directly to access data or serialize data to the server. Jake Archibald has an excellent post … Read more

tech