Search code examples
windows-phone-7windows-phone-7.1

How to call a PHP file using Windows Phone application?


I want to create a simple login functionality in WP7 app using remote MySQL database using PHP as back-end. I have never used this in C#, so I don't know how to do this.


Solution

  • You can use WebClient or HttpWebRequest class to make a web request and get the response.

    Here is a sample code on how to make a request and get response

    WebClient client = new WebClient();
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    client.DownloadStringAsync(new Uri("http://someurl", UriKind.Absolute));
    

    And the asynchronous response handler is here

    void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        var response= e.Result; // Response obtained from the web service  
    }
    

    The above example works for any web service(it may be PHP or jsp or asp etc).

    All that you need to do is to make a proper request and handling the response