Error 500 with Google AppEngine, and class java.net -
i have problem gae. have application http://www.similarityface.appspot.com/query. trying through program in java communicate application perform query, via post method. problem generating 500 error. code below, me telling i'm doing wrong.
public class vetores_facebook { public static void main(string[] args) throws unsupportedencodingexception, ioexception { final string server = "https://www.similarityface.appspot.com/query"; url url = null; try { url = new url(server); } catch (malformedurlexception ex) { logger.getlogger(vetores_facebook.class.getname()).log(level.severe, null, ex); } httpurlconnection urlconn = null; try { // url connection channel. urlconn = (httpurlconnection) url.openconnection(); } catch (ioexception ex) { logger.getlogger(vetores_facebook.class.getname()).log(level.severe, null, ex); } urlconn.setdooutput (true); // no caching, want real thing. urlconn.setusecaches (false); try { urlconn.setrequestmethod("post"); } catch (protocolexception ex) { logger.getlogger(vetores_facebook.class.getname()).log(level.severe, null, ex); } try { urlconn.connect(); } catch (ioexception ex) { logger.getlogger(vetores_facebook.class.getname()).log(level.severe, null, ex); } string message = urlencoder.encode("get_object(\"me\", metadata=1)", "utf-8"); try (outputstreamwriter writer = new outputstreamwriter(urlconn.getoutputstream())) { writer.write(message); writer.close(); } if (urlconn.getresponsecode() == httpurlconnection.http_ok) { system.out.println("ok"); } else{ int x = urlconn.getresponsecode(); system.out.println("error "+x); } } }
try { urlconn.connect(); } catch (ioexception ex) { logger.getlogger(vetores_facebook.class.getname()).log(level.severe, null, ex); } string message = urlencoder.encode("get_object(\"me\", metadata=1)", "utf-8"); try (outputstreamwriter writer = new outputstreamwriter(urlconn.getoutputstream())) { writer.write(message); writer.close(); }
the problem calling urlconn.connect(); seems flush output buffers may have , prepares connection input stream. trying write open output stream after cause exception.
use example given here correct way this: https://developers.google.com/appengine/docs/java/urlfetch/usingjavanet#using_httpurlconnection
Comments
Post a Comment