Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2016
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. URL url = new URL("http://192.168.43.226:8080/Manager/LogInServlet?username=" + this.theUserName + "&password=" + this.thePassword);
  2.                 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  3.                 urlConnection.setRequestMethod("POST");
  4.                 urlConnection.setDoOutput(true);
  5.                 urlConnection.setDoInput(true);
  6.                 try {
  7.                     urlConnection.setRequestProperty("Cookie", cookie);
  8.                     InputStream in = new BufferedInputStream(urlConnection.getInputStream());
  9.                     cookie = urlConnection.getHeaderField("Set-Cookie");
  10.  
  11.                     BufferedReader streamReader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
  12.                     StringBuilder responseStrBuilder = new StringBuilder();
  13.  
  14.                     String inputStr;
  15.                     while ((inputStr = streamReader.readLine()) != null)
  16.                         responseStrBuilder.append(inputStr);
  17.  
  18.                     JSONObject json = new JSONObject(responseStrBuilder.toString());
  19.  
  20.                     return new Answer(json);
  21.                 } catch (IOException e) {
  22.                     e.printStackTrace();
  23.                 } finally {
  24.                     urlConnection.disconnect();
  25.                 }
  26.             } catch (Exception e) {
  27.                 e.printStackTrace();
  28.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement