Java - HttpUrlConnection -
Java - HttpUrlConnection -
hi i've started using httpurlconnection
, have question regarding on when http request sent.
i read somewhere actual request sent when getinputstream()
called. however, i've written test code play around post request:
in version i'm calling on getresponsecode()
before getinputstream()
url obj = new url(myurl); httpurlconnection httpclient = (httpurlconnection) obj.openconnection(); httpclient.setrequestmethod("post"); **int responsecode = httpclient.getresponsecode();** seek { instream = httpclient.getinputstream(); } grab (ioexception ie) { instream = httpclient.geterrorstream(); } system.out.println("response code = " + responsecode);
i receive response code of 200. got me thinking request not beingness sent @ getinputstream(), @ before method. have insight on this?
thanks!
code insight httpurlconnection#getresponsecode()
- openjdk 7
public int getresponsecode() throws ioexception { 454 /* 455 * we're got response code 456 */ 457 if (responsecode != -1) { 458 homecoming responsecode; 459 } 460 461 /* 462 * ensure have connected server. record 463 * exception need re-throw if there isn't 464 * status line. 465 */ 466 exception exc = null; 467 seek { 468 getinputstream(); 469 } grab (exception e) { 470 exc = e; 471 } 472 ...
basically response code
-1 @ initialization means have not got response code. found connection url#getinputstream()
, response code.
java httpurlconnection
Comments
Post a Comment