android - Receiving "501 Not Implemented" when using HttpURLConnection -


my project targeted sdk 23, , on, far know, have use httpurlconnection instead of httpclient make post requests, keep getting 501 response code webservice (i'm pretty sure it's functional, have no doubt) when making post requests store users in remote mysql database. here follows main connection code:

class databaseconnector extends asynctask<string, void, string> {     private final string connection_url = "webservice_address";      @override     protected string doinbackground(string... params) {         string response = "initial value";          try {             url url = new url(connection_url);              httpurlconnection con = (httpurlconnection) url.openconnection();             con.setdooutput(true);             con.setdoinput(true);             con.setusecaches(false);             con.setrequestproperty("content-type", "application/json");             con.setrequestproperty("accept", "application/json");             con.setreadtimeout(10000);             con.setconnecttimeout(15000);             con.setrequestmethod("post");              jsonobject json = new jsonobject();              json.put("query", params[0]);              jsonobject conn = new jsonobject();             conn.put("database", "database");             conn.put("hostname", "hostname");             conn.put("password", "password");             conn.put("username", "username");             conn.put("port", "port");              json.put("conn", conn.tostring());              outputstreamwriter wr = new outputstreamwriter(con.getoutputstream());             wr.write(json.tostring());             wr.flush();             wr.close();              con.connect();              //display returns post request              stringbuilder sb = new stringbuilder();             int httpresult = con.getresponsecode();              system.out.println("response code: "+ con.getresponsecode());              if (httpresult == httpurlconnection.http_ok) {                 system.out.println("passed1");                 bufferedreader br = new bufferedreader(new inputstreamreader(con.getinputstream(), "utf-8"));                  while ((response = br.readline()) != null) {                     sb.append(response + "\n");                 }                  br.close();                  system.out.println("e: " + sb.tostring());                  response = sb.tostring();             } else {                 system.out.println("e2: "+con.getresponsemessage());                 response = "error1: "+con.getresponsemessage();             }         } catch (exception e) {             response = "error2: "+e.tostring();         }          return response;     } } 

and in fragment make network calls:

try {     string result = new databaseconnector().execute("selecsst 1").get();     toast.maketext(contentactivity.this, "result: "+result, toast.length_long).show(); } catch (exception ex) {     toast.maketext(contentactivity.this, "error3: "+ex.tostring(), toast.length_long).show(); } 

nevermind wrong sql statement, it's meant that, want webservice echo syntax error. have tried many stuff, codes, examples, doesn't seem work.

the point is: keep getting error code 501 not implemented. why? , how can fix that?

edit:

any tips or comments on how improve way make network calls on android welcome, i'm pretty new that. i'm using async call somehow it's still executing in main thread, cause debugger complains:

09-25 19:17:32.714  28853-28853/br.com.developer.package i/choreographer﹕ skipped 80 frames!  application may doing work on main thread. 

thank all.


Comments