Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone!

I begin a project in windows phone 8 and i have a little probleme with the connection to server.. my GetResponseCallback doesn't work and i don't know why :/
Sorry for noob question, if somebody can help me. It would be nice ^^

I put my code here.

thank you :)


C#
public partial class Login : PhoneApplicationPage
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Login_Click(object sender, RoutedEventArgs e)
        {
            SendRequest(Box_email.Text, PasswordBox.Password);
        }

        public void SendRequest(String email, String mdp)
        {
            // Create a new HttpWebRequest object.
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://19.334.35.55/eip/api/web/app.php/oauth/v2/token?");

            string _url = "http://19.334.35.55/eip/api/web/app.php/oauth/v2/token?";
            string _email = "Username=" + email;
            string _mdp = "password=" + mdp;
            request.ContentType = _url + _email + _mdp;
            request.Method = "GET";

            MessageBox.Show("point A debug");
            request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
            allDone.WaitOne();
        }


        private void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            //   Dispatcher.BeginInvoke(() =>
            //  {
            //      MessageBox.Show("inside get response");
            // });
            
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            if (request != null)
            {

                try
                {
                    // End the operation
                    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

                    Stream streamResponse = response.GetResponseStream();

                    StreamReader streamRead = new StreamReader(streamResponse);
                    string responseString = streamRead.ReadToEnd();
                    Console.WriteLine(responseString);
                    // Close the stream object
                    streamResponse.Close();
                    streamRead.Close();

                    // Release the HttpWebResponse
                    response.Close();
                    allDone.Set();
                }
                catch (WebException e)
                {
                    MessageBox.Show("probleme");
                    return;
                }
            }
            
        }
Posted
Updated 23-Dec-14 2:00am
v2

1 solution

You can follow this tutorial which will help you to do this task:
Calling REST Services from a Windows Phone 8 App[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900