Rdb
Rdb

Reputation: 43

Connect to website with Windows Phone 7

I'm developing a project for windows phone 7. It's very simple I guess but I don't know very well C# especially C# for wp7.

I have an existing php page with this code

<?php
if(isset($_GET['name'])) {
    $ssid=$_GET['name'];
}
$name .= "Hello";
?>

I want to make a wp7 application where I can write a name in text, press the button to connect to server, pass the name in the text as php parameter and write server response in another text on mobile screen. How can I do this?

Upvotes: 1

Views: 932

Answers (3)

Morti
Morti

Reputation: 717

Create an HttpWebRequest with your query :

private void MyMethod(Action action){

   HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://website/page.php?name={0}",name));
            webRequest.BeginGetResponse((callBack)=>{
            HttpWebRequest request = (HttpWebRequest)callBack.AsyncState;
                                    WebResponse webResponse = request.EndGetResponse(callBack);
        using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
                    {
                        string response = string.Empty;
                        try
                        {
                            response = sr.ReadToEnd();
                        }
                        catch (Exception ex)
                        {
                            response = ex.Message;
                        }
                        action.Invoke(response);

                    }
webResponse.Close();

            },webRequest)

} where textresponse is your server response

Upvotes: 0

Pavan Kumar
Pavan Kumar

Reputation: 206

Try this one, it helps you

in first page or form,

NavigationService.Navigate(new Uri("/Projectname;component/pagename.xaml?name=" + variable1 + "&country="+variable2, UriKind.Relative));

in second page or form,

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

{

        base.OnNavigatedTo(e);
        string myname = NavigationContext.QueryString["name"];
        string Mycountry = int.Parse(NavigationContext.QueryString["country"]);

}

The 'name' and 'country' in OnNavigatedTo are same as navigateservice

In this way you send values from one page to another page.

Upvotes: 0

Stevanicus
Stevanicus

Reputation: 7761

Something like this perhaps?

POST Request

Try this (read the first comment tho... author made a typo):

Post Request

Upvotes: 2

Related Questions