Advertisement
Guest User

HtttpGetAndroid Example

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