Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public AdressAsync(Context _context) {
  2. this.context = _context;
  3. }
  4. @Override
  5. protected void onPreExecute() {
  6. super.onPreExecute();
  7. }
  8.  
  9. @Override
  10. protected Integer doInBackground(Integer... params) {
  11. try {
  12. ConnectAdressTest();
  13. res = 1;
  14. } catch (Exception e) {
  15. e.printStackTrace();
  16. }
  17. finally {
  18. return res;
  19. }
  20. }
  21.  
  22. @Override
  23. protected void onProgressUpdate(Integer... values) {
  24. }
  25.  
  26. @Override
  27. protected void onPostExecute(Integer result) {
  28. }
  29.  
  30. public void ConnectAdressTest() {
  31. try {
  32. String name = "name";
  33. String password = "password";
  34. String url = "http://10.0.2.2:60308/api/GetUserInfo";
  35. String authString = name + ":" + password;
  36. System.out.println("auth string: " + authString);
  37. String authEncBytes = Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);
  38. String authStringEnc = new String(authEncBytes);
  39. System.out.println("Base64 encoded auth string: " + authStringEnc);
  40.  
  41. Log.i("TEST", "ConnectAdressTest 2");
  42. URL url2 = new URL(url);
  43. URLConnection urlConnection = url2.openConnection();
  44. urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
  45. Log.i("TEST", "ConnectAdressTest 3");
  46.  
  47. // int code = urlConnection..getResponseCode();
  48. InputStream is = urlConnection.getInputStream();
  49. Log.i("TEST", "ConnectAdressTest 4");
  50.  
  51. InputStreamReader isr = new InputStreamReader(is);
  52.  
  53. Log.i("TEST", "ConnectAdressTest 5");
  54.  
  55. /* HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
  56.  
  57. connection.setUseCaches(false);
  58.  
  59. connection.connect();
  60.  
  61. final String basicAuth = "Basic " + Base64.encodeToString("username:pass".getBytes(), Base64.NO_WRAP);
  62.  
  63. connection.setRequestProperty ("Authorization", basicAuth);*/
  64. }
  65. } catch (MalformedURLException e) {
  66. e.printStackTrace();}
  67. } catch (IOException e) {
  68. Log.d("Exception: ", "IOException");
  69. }
  70. } catch (Exception e) {
  71. e.printStackTrace();
  72. }
  73. finally {
  74. Log.i("TEST", "Post execute finally");
  75. }
  76. }
  77.  
  78. <binding protocol="http" bindingInformation="*:60308:10.0.2.2" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement