Advertisement
Guest User

HtttpGetAndroid Example

a guest
May 10th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using Android.App;
  2. using System.IO;
  3. using Android.OS;
  4. using System.Net;
  5. using System.Text;
  6. using Android.Widget;
  7.  
  8. namespace HttpTest
  9. {
  10.     [Activity(Label = "HttpGetAndroid", MainLauncher = true, Icon = "@drawable/icon")]
  11.     public class MainActivity : Activity
  12.     {
  13.         protected override void OnCreate(Bundle bundle)
  14.         {
  15.             base.OnCreate(bundle);
  16.             SetContentView(Resource.Layout.Main);
  17.  
  18.             TextView MessageLabel = FindViewById<TextView>(Resource.Id.SecondName);
  19.             EditText NameTxt = FindViewById<EditText>(Resource.Id.Name);
  20.             EditText SecondName = FindViewById<EditText>(Resource.Id.SecondName);
  21.             Button SendBtn = FindViewById<Button>(Resource.Id.Send);
  22.            
  23.             string user = "VistaVerde";
  24.             string password = "VistaVerdaPasswordExample";
  25.  
  26.             SendBtn.Click += delegate
  27.             {
  28.                 WebRequest get = WebRequest.Create("http://186.15.27.24/usersdata.php");
  29.                 get.Method = "GET";
  30.                 get.Credentials = new NetworkCredential(user, password);                
  31.                 WebResponse res = get.GetResponse();
  32.                 StreamReader io = new StreamReader(res.GetResponseStream(), Encoding.ASCII);
  33.                 if (io.ReadToEnd().Contains(NameTxt.Text))
  34.                     MessageLabel.Text = "Este usuario ya ha sido registrado";
  35.                 else
  36.                     MessageLabel.Text = "Este usuario esta disponible";
  37.             };
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement