Advertisement
Guest User

Untitled

a guest
May 19th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. try {
  2.                  URL url = new URL(API_URL + "apikey=" + API_KEY + "&username=" + email + "&password=" + password);
  3.                 //http://staging.symptoma.com/api/v2/ping?apikey=9b5e5c01f2eb86bb3882af9dbab21ca1
  4.                 //URL url = new URL(API_URL + "apikey=" + API_KEY);
  5.                 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  6.                 urlConnection.setRequestMethod("GET");
  7.                 //urlConnection.setRequestProperty("Authorization","Basic" + encoding);
  8.                 //urlConnection.setDoOutput(false);
  9.                 Authenticator.setDefault(new CustomAuthenticator());
  10.                 urlConnection.connect();
  11.                 int status = urlConnection.getResponseCode();
  12.  
  13.                 if (status >= 400) {
  14.                     if (status == 404 || status == 410) {
  15.                         throw new FileNotFoundException(url.toString());
  16.                     } else {
  17.                         throw new java.io.IOException(
  18.                                 "Server returned HTTP"
  19.                                         + " response code: " + status
  20.                                         + " for URL: " + url.toString());
  21.                     }
  22.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement