android - HttpStatus become deprecated in API level 22 -


usually used check server different code responses in restclient class using org.apache.http.httpstatus class following example:

if (httpstatus.sc_ok == restclient.getresponsecode()) {             //200 ok (http/1.0 - rfc 1945)             return true; } else if (httpstatus.sc_bad_gateway == restclient.getresponsecode()){            //502 bad gateway (http/1.0 - rfc 1945)             return false; } 

but class became deprecated since api level 22 according official documentation

this interface deprecated in api level 22. please use openconnection() instead. please visit webpage further details.

but using openconnection() method me not make sense.

my question is: there other way same functionality without needing hardcode code responses myself within application?

thanks in advance.

you can cast returned value of openconnection httpurlconnection, , use getresponsecode() retrieve response code

httpurlconnection urlconnection = (httpurlconnection) url.openconnection(); final int responsecode = urlconnection.getresponsecode(); if (responsecode == httpurlconnection.http_ok) {  } else if (responsecode == httpurlconnection.http_bad_gateway) {  } 

httpurlconnection.getresponsecode() documentation here


Comments

Popular posts from this blog

java - Incorrect order of records in M-M relationship in hibernate -

command line - Use qwinsta in PowerShell ISE -

php - I want to create a website for polls/survey like this http://www.poll-maker.com/ -