android - Can't send multpart/form-data with Volley -
i have problem send params in body request. on postman have successful request using volley unexpected response code 415 error code.
postman automatically generates random boundary text gets added body params when sending request. missing on code. here's how might it:
use random boundary server use split params
val boundary = "as24adije32mdjhem9omagnkuxtfhq" val multipart_formdata = "multipart/form-data;boundary=" + boundary getbodycontenttype function should return multipart_formdata
override fun getbodycontenttype(): string { return multipart_formdata } on getbody() function, add boundary params this:
override fun getbody(): bytearray { val params = hashmap<string, string>() params.put("profile_id", "1") params.put("place_name", "la la land") params.put("place_identifier", "10239jodmda") val map: list<string> = params.map { (key, value) -> "--$boundary\ncontent-disposition: form-data; name=\"$key\"\n\n$value\n" } val endresult = "${map.jointostring("")}\n--$boundary--\n" return endresult.tobytearray() } since setting content type on getbodycontenttype(), don't need following line on getheaders():
headers.put("content-type", "multipart/form-data") this answer shows how similar in java: https://stackoverflow.com/a/38238994/3189164


Comments
Post a Comment