java - Error: UnsupportedCharsetException when upload file with MultipartEntity entity -
i send form server, text field , file edittext. think send wrong shape. form of sending browser:
post /wp-content/themes/reverie-master/contacts.php http/1.1 host: ukp.mogilev.by connection: keep-alive content-length: 47504 origin: http://ukp.mogilev.by user-agent: mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, gecko) chrome/54.0.2840.99 safari/537.36 content-type: multipart/form-data; boundary=----webkitformboundaryh00meqz9l5bbl7bz accept: */* dnt: 1 referer: http://ukp.mogilev.by/elektronnye-obrashcheniya-grazhdan/ accept-encoding: gzip, deflate accept-language: ru-ru,ru;q=0.8,en-us;q=0.6,en;q=0.4 cookie: _ym_uid=1478194399500303049; _ym_isad=1; _ym_visorc_28369546=w request payload ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="nameff" отправка с пк,тест ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="gorodff" отправка с пк,тест ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="streetff" отправка с пк,тест ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="homeff" отправка с пк,тест ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="contactff" q@tut.by ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="messageff" отправка с пк,тест ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="fileff[]"; filename="instruction 3.1.png" content-type: image/png ------webkitformboundaryh00meqz9l5bbl7bz content-disposition: form-data; name="fileff[]"; filename="" content-type: application/octet-stream ------webkitformboundaryh00meqz9l5bbl7bz--
i upload file asynctask.
private string uploadfile() { string responsestring = null; httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(upload_url); multipartentity entity = new multipartentity( httpmultipartmode.browser_compatible); try { file filepathstorage = new file(getpath(filepath));//путь к файлу filename = filepathstorage.getname();//имя файла file path = environment.getexternalstoragepublicdirectory( environment.directory_pictures); //file sendingfile = new file(path, filename); filebody body = new filebody(filepathstorage, "content-type: image/jpeg", filename); entity.addpart(key_name, new stringbody(name)); entity.addpart(key_naselpunkt, new stringbody(naselpunkt)); entity.addpart(key_street, new stringbody(street)); entity.addpart(key_dom, new stringbody(house)); entity.addpart(key_email, new stringbody(e_mail)); entity.addpart(key_mesages, new stringbody(message)); entity.addpart(key_image, body);// public static final string key_image = "fileff[]"; log.e("result_otvet_entity", "response server: " + entity); httppost.setentity(entity); httpresponse response = httpclient.execute(httppost); httpentity r_entity = response.getentity(); bufferedreader reader = new bufferedreader(new inputstreamreader(response.getentity().getcontent(), "utf-8")); string sresponse; stringbuilder s = new stringbuilder(); while ((sresponse = reader.readline()) != null) { s = s.append(sresponse); } log.v("response post", s.tostring()); int statuscode = response.getstatusline().getstatuscode(); if (statuscode == 200) { // server response responsestring = entityutils.tostring(r_entity); } else { urldecoder.decode(urlencoder.encode(responsestring, "iso8859-1"), "utf-8"); responsestring = "error occurred! http status code: " + statuscode; } } catch (ioexception e) { responsestring = e.tostring(); } return responsestring; }
in log see error:
caused by: java.nio.charset.unsupportedcharsetexception: img_20161115_113532.jpg
the error in line
filebody body = new filebody(filepathstorage, "content-type: image/jpeg", filename);
try change parameter in filebody constructor: filebody(filepathstorage, contenttype.multipart_form_data, filename);
Comments
Post a Comment