java - POST HttpRequest using MultipartEntityBuilder and without deprecated classes -


i use method on code , works fine, since api22 httpost, httpclient, httpentity... deprecated.

i know correct update of code using httpurlconnection don't know how use parameters on multipartentitybuilder.

public jsonobject makehttprequest(string url, multipartentitybuilder datos) {     httpclient httpclient = new defaulthttpclient();           try {         httppost httppost = new httppost(url);         httppost.setentity(datos.build());         httpresponse httpresponse = httpclient.execute(httppost);         httpentity httpentity = httpresponse.getentity();         inputstream = httpentity.getcontent();     } catch (unsupportedencodingexception e) {         e.printstacktrace();     } catch (clientprotocolexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }     return inputstreamtojson(is); } 

edit: so, changed code , deprecated class httpentity, keep searching, updated code:

public jsonobject makehttprequest(string url, multipartentitybuilder datos) {     try {         httpentity entity = datos.build();         httpurlconnection conn = (httpurlconnection) new url(url).openconnection();         conn.setusecaches(false);         conn.setdooutput(true);         conn.setdoinput(true);         conn.setrequestmethod("post");         conn.setrequestproperty("accept-charset", "utf-8");         conn.setrequestproperty("connection", "keep-alive");         conn.setrequestproperty("cache-control", "no-cache");         conn.setrequestproperty("content-length", entity.getcontentlength() + "");         conn.setrequestproperty(entity.getcontenttype().getname(), entity.getcontenttype().getvalue());         outputstream os = conn.getoutputstream();         entity.writeto(os);         os.close();         inputstream = conn.getinputstream();     } catch (malformedurlexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }     return inputstreamtojson(is); } 

please refer android httpurlconnection send post , params request


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -