java - Android HttpURLConnection POST not working -


i have problem parameters passed url post. when in php try retrieve them says $_post empty:

<?php require_once 'credentials.php'; $connection = mysqli_connect(mysql_host, mysql_user, mysql_pass, mysql_database); $query = 'insert ratings (disco, rating) values (' .mysqli_real_escape_string($connection, $_post["disco"]). ', ' . mysqli_real_escape_string($connection, $_post["rating"]) . ')'; $result = mysqli_query($connection, $query); echo json_encode($result); mysqli_close($connection);   ?> 

and android code looks this:

@override             protected string doinbackground(string... params) {                 string response = "";                 try {                     url url = new url(params[0]);                     httpurlconnection urlconnection = (httpurlconnection)url.openconnection();                     urlconnection.setconnecttimeout(10000);                     urlconnection.setreadtimeout(10000);                     urlconnection.setdooutput(true);                     urlconnection.setrequestmethod("post");                     urlconnection.setdooutput(true);                     urlconnection.setdoinput(true);                     urlconnection.connect();                      list<namevaluepair> parameters = new arraylist<namevaluepair>();                     parameters.add(new basicnamevaluepair("disco", params[1]));                     parameters.add(new basicnamevaluepair("rating", params[2]));                      outputstream outputstream = urlconnection.getoutputstream();                     bufferedwriter writer = new bufferedwriter(new outputstreamwriter(outputstream, "utf-8"));                     writer.write(getquery(parameters));                     writer.flush();                     writer.close();                     outputstream.close();                     int responsecode = urlconnection.getresponsecode();                     if(responsecode == httpurlconnection.http_ok) {                         string line;                         bufferedreader br=new bufferedreader(new inputstreamreader(urlconnection.getinputstream()));                         while((line = br.readline()) != null) {                             response += line;                         }                     }                 } catch(exception e) {                     system.out.println(e.getmessage());                 }                 return response;             }              private string getquery(list<namevaluepair> params) throws unsupportedencodingexception {                 stringbuilder result = new stringbuilder();                 boolean first = true;                  for(namevaluepair pair : params) {                     if(first)                         first = false;                     else                         result.append("&");                      result.append(urlencoder.encode(pair.getname(), "utf-8"));                     result.append("=");                     result.append(urlencoder.encode(pair.getvalue(), "utf-8"));                 }                  return result.tostring();             } 

what's wrong this? in advance

edit: updated code , still doesn't work.

"&disco=" 

make that:

"disco=" 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -