Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public AdressAsync(Context _context) {
- this.context = _context;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- }
- @Override
- protected Integer doInBackground(Integer... params) {
- try {
- ConnectAdressTest();
- res = 1;
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- return res;
- }
- }
- @Override
- protected void onProgressUpdate(Integer... values) {
- }
- @Override
- protected void onPostExecute(Integer result) {
- }
- public void ConnectAdressTest() {
- try {
- String name = "name";
- String password = "password";
- String url = "http://10.0.2.2:60308/api/GetUserInfo";
- String authString = name + ":" + password;
- System.out.println("auth string: " + authString);
- String authEncBytes = Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);
- String authStringEnc = new String(authEncBytes);
- System.out.println("Base64 encoded auth string: " + authStringEnc);
- Log.i("TEST", "ConnectAdressTest 2");
- URL url2 = new URL(url);
- URLConnection urlConnection = url2.openConnection();
- urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
- Log.i("TEST", "ConnectAdressTest 3");
- // int code = urlConnection..getResponseCode();
- InputStream is = urlConnection.getInputStream();
- Log.i("TEST", "ConnectAdressTest 4");
- InputStreamReader isr = new InputStreamReader(is);
- Log.i("TEST", "ConnectAdressTest 5");
- /* HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
- connection.setUseCaches(false);
- connection.connect();
- final String basicAuth = "Basic " + Base64.encodeToString("username:pass".getBytes(), Base64.NO_WRAP);
- connection.setRequestProperty ("Authorization", basicAuth);*/
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();}
- } catch (IOException e) {
- Log.d("Exception: ", "IOException");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- Log.i("TEST", "Post execute finally");
- }
- }
- <binding protocol="http" bindingInformation="*:60308:10.0.2.2" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement