database - Java URL doesn't seem to connect, but no exception thrown -


i have code needs form connection server, , once connection formed server interprets string sent , updates names in database. i.e. send "http://app.sitename.tv/api/add/aname" , adds "aname" database, or send "http://app.sitename.tv/api/remove/aname" , removes name.

when type these links browser , run it works fine. program, though, doesn't throw exceptions not update database. i'm not sure go here. i've tried turning off firewall makes no difference.

if ((boolean) value) {     system.out.println("setvalue");     try      {         string bvurl = "http://app.sitename.tv/api/add/" + data.name.get(row);         url myurl = new url(bvurl);         urlconnection myurlconnection = myurl.openconnection();         myurlconnection.connect();         system.out.println(bvurl);     }      catch (malformedurlexception e)      {          system.err.println("malformedurlexception: " + e);     }      catch (ioexception e)      {            system.err.println("ioexception: " + e);     } } else if ((boolean) value == false) {     system.out.println("setvalue");     try      {         string bvurl = "http://app.sitename.tv/api/remove/" + data.name.get(row);         url myurl = new url(bvurl);         urlconnection myurlconnection = myurl.openconnection();         myurlconnection.connect();         system.out.println(bvurl);     }      catch (malformedurlexception e)      {          system.err.println("malformedurlexception: " + e);     }      catch (ioexception e)      {            system.err.println("ioexception: " + e);      } } 

the urlconnection getting httpurlconnection. have opened connection not closed it. request httpurlconnection closed, should call disconnect() method. connection needs closed in order ensure server receives request , processes it.

for example, can replace first try/catch block this:

httpurlconnection myurlconnection = null; try {     string bvurl = "http://app.sitename.tv/api/add/" + data.name.get(row);     url myurl = new url(bvurl);     myurlconnection = (httpurlconnection) myurl.openconnection();     myurlconnection.connect();     system.out.println(bvurl); } catch (malformedurlexception e) {      system.err.println("malformedurlexception: " + e); } catch (ioexception e) {        system.err.println("ioexception: " + e); } {     if (myurlconnection != null) {         myurlconnection.disconnect();         myurlconnection = null;     } } 

if still not work, may need inputstream connection, using getinputstream(), , consume input data before disconnecting.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -