Windows phone 7 submits a URL through Post to the server and obtains data from the server (for example, used during login)

Source: Internet
Author: User
HttpWebRequest myRequest = (HttpWebRequest) WebRequest.Create (UrlManager.Login ());
            myRequest.Method = "POST";
            myRequest.ContentType = "application / x-www-form-urlencoded";

            myRequest.BeginGetRequestStream (new AsyncCallback (GetRequestStreamCallback), myRequest);



private void GetRequestStreamCallback (IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest) asynchronousResult.AsyncState;
            System.IO.Stream postStream = request.EndGetRequestStream (asynchronousResult);

            // Prepare Parameters String
            string parametersString = "username = Username & password = Password";
            // foreach (KeyValuePair <string, string> parameter in parameters)
            // {
            // parametersString = parametersString + (parametersString! = ""? "&": "") + string.Format ("{0} = {1}", parameter.Key, parameter.Value);
            //}

         

            byte [] byteArray = System.Text.Encoding.UTF8.GetBytes (parametersString);
            // Write to the request stream.
            postStream.Write (byteArray, 0, parametersString.Length);
            postStream.Close ();
            // Start the asynchronous operation to get the response
            request.BeginGetResponse (new AsyncCallback (GetResponseCallback), request);
        }



 private void GetResponseCallback (IAsyncResult asynchronousResult)
        {
            HttpWebRequest request = (HttpWebRequest) asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse) request.EndGetResponse (asynchronousResult);
            Stream streamResponse = response.GetResponseStream ();
            StreamReader streamRead = new StreamReader (streamResponse);
            string responseString = streamRead.ReadToEnd ();
            // Close the stream object
            streamResponse.Close ();
            streamRead.Close ();
       } 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.