Advertisement
Guest User

Untitled

a guest
May 1st, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. try{
  2. String account = params[0].get(0);
  3. String password = params[0].get(1);
  4.  
  5. URL url = new URL("http", WEB_SERVICE_URL, PORT, REST_LOGIN);
  6. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  7. httpURLConnection.setConnectTimeout(CONNECTION_TIMEOUT);
  8.  
  9.  
  10. httpURLConnection.setRequestMethod("POST");
  11.  
  12.  
  13. httpURLConnection.setDoOutput(true);
  14. httpURLConnection.setRequestProperty("Content-Type", "application/json");
  15. httpURLConnection.setRequestProperty("Accept", "application/json");
  16.  
  17. JSONObject json = jsonParser.serialJsonLogin(nomCompte, motPasse);
  18.  
  19.  
  20. osw = new OutputStreamWriter(httpURLConnection.getOutputStream(),"UTF-8");
  21. osw.write(json.toString());
  22. osw.flush();
  23. String body = readStream(httpURLConnection.getInputStream());
  24. osw.close();
  25.  
  26.  
  27.  
  28.  
  29. Log.i(TAG, "Return : " + body);
  30.  
  31. user = jsonParser.deserializeJsonUser(body);
  32.  
  33. }catch (Exception e) {
  34. mException = e;
  35. }finally {
  36. if (mHttpURLConnection != null) {
  37. mHttpURLConnection.disconnect();
  38. }
  39. }
  40. return user;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement