java - HttpUrlConnection either 'unauthorized' or 'already connected' -


i've got problem httpurlconnection.

i want download file internet.
first time works perfectly.
when try again, have exception i'm "already connected", or "connect in progress".

exception in thread "main" java.lang.illegalstateexception: connect in  progress 

i googled , found need remove things con.setdooutput(true);. did , reboot program. i've got exception: 401 unauthorized.

i don't see do. code:

public boolean creersession(string endpoint) throws ioexception, jsonexception, interruptedexception {     // ouverture de la connexion     string url = new stringbuilder(endpoint).append("/auth").tostring();     url obj = new url(url);     validerall();     httpurlconnection con = (httpurlconnection) obj.openconnection();      // définition des request header     string urlparameters = new stringbuilder("username=").append(this.login).append("&password=").append(this.password).tostring();             con.setrequestmethod("post");     con.getrequestmethod();      // envoi de la requete en post     con.setdooutput(true);     dataoutputstream wr = new dataoutputstream(con.getoutputstream());     wr.writebytes(urlparameters);     wr.flush();     wr.close(); 

any idea?

@emanuele giona you're right, disconnect() missing, if try that, error follows. @quitium that's explained: if uncomment code

con.setrequestmethod("post"); con.getrequestmethod(); con.setdooutput(true); 

i have unauthorized exception

stack trace (first time it's ok, few minutes later, problem connect in progress comes back...)

connected target vm, address: '127.0.0.1:61323', transport: 'socket' ticket de la session : xizzaxwt36k0+lreivdko6ijkitlwdwl1kx1eg1tiggv3fj3gw/in9zkbhtrjutvwupmah3xpq1jrkbyj50url0sn1vddze+grinhfiif4tombqxwskipa== exception in thread "main" java.lang.illegalstateexception: connect in progress @ sun.net.www.protocol.http.httpurlconnection.setrequestmethod(httpurlconnection.java:517) @ sun.net.www.protocol.https.httpsurlconnectionimpl.setrequestmethod(httpsurlconnectionimpl.java:374) @ gedwstesting.downloadfile(gedwstesting.java:60) @ gedwstesting.main(gedwstesting.java:32) disconnected target vm, address: '127.0.0.1:61323', transport: 'socket'

process finished exit code 1

my code (lines 57 → 64)

// open connection     httpurlconnection con = (httpurlconnection) downloadurl.openconnection();     con.setrequestproperty("cookie", "llcookie=" + mainsession.getticket() + "; path=/livelink/; secure");     con.setrequestmethod("head");     con.setinstancefollowredirects(false);     con.setreadtimeout(50000);     con.setconnecttimeout(10000);     con.connect(); 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -