urlencode - On Android, make a POST request with URL Encoded Form data without using UrlEncodedFormEntity -


i have string in proper urlencoded form format , send through post request on android php server. know method sending url encoded forms on android uses urlencodedformentity , know how use it. problem data comes function url encoded , joined ampersands, using urlencodedformentity involve lot of work turn list of namevaluepairs , i'd rather not.

so, how make proper post request sending string content body?

i have tried using stringentity, php server didn't of data (empty $_post object).

i testing against http://test.lifewanted.com/echo.json.php is

<?php echo json_encode( $_request ); 

here example of already-encoded data:

partneruserid=email%40example.com&partnerusersecret=mypassword&command=authenticate

if don't mind using httpurlconnection instead of (recommended) httpclient way:

public void performpost(string encodeddata) {     httpurlconnection urlc = null;     outputstreamwriter out = null;     dataoutputstream dataout = null;     bufferedreader in = null;     try {         url url = new url(url_login_submit);         urlc = (httpurlconnection) url.openconnection();         urlc.setrequestmethod("post");         urlc.setdooutput(true);         urlc.setdoinput(true);         urlc.setusecaches(false);         urlc.setallowuserinteraction(false);         urlc.setrequestproperty(header_user_agent, header_user_agent_value);         urlc.setrequestproperty("content-type","application/x-www-form-urlencoded");         dataout = new dataoutputstream(urlc.getoutputstream());         // perform post operation         dataout.writebytes(encodeddata);         int responsecode = urlc.getresponsecode();         in = new bufferedreader(new inputstreamreader(urlc.getinputstream()),8096);         string response;         // write html system.out debug         while ((response = in.readline()) != null) {             system.out.println(response);         }         in.close();     } catch (protocolexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } {         if (out != null) {             try {                 out.close();             } catch (ioexception e) {                 e.printstacktrace();             }         }         if (in != null) {             try {                 in.close();             } catch (ioexception e) {                 e.printstacktrace();             }         }     } } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -