using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Net.NetworkInformation;

namespace WebRequest_Extensions
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            WebRequest request = WebRequest.Create("http://192.168.2.113/");
            request.SetNetworkRequirement(NetworkSelectionCharacteristics.Cellular);
            request.BeginGetResponse(result =>
            {
                try
                {
                    WebResponse response = request.EndGetResponse(result);
                }
                catch (WebException ex)
                {
                    
                    Deployment.Current.Dispatcher.BeginInvoke(()=>
                    MessageBox.Show(ex.Message)
                    );
                }
            }, null);
        }
    }
}