HttpClient and HttpGet Support in WP7

前端 未结 3 1778
离开以前
离开以前 2021-01-17 06:56

I am building an app which is already build in Android & other Mobile Platform. Since the App uses REST based Webservices build in JAVA, thus I need to use these Webserv

相关标签:
3条回答
  • 2021-01-17 07:32

    You can use HttpWebRequest ( http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.95).aspx ) to make calls to a REST service

    0 讨论(0)
  • 2021-01-17 07:38

    I would recommend using the WebClient class for simple HTTP based communication. Here is the basic format I typically use when making a request to a web service:

    WebClient web = new WebClient();
    web.OpenReadCompleted += new OpenReadCompletedEventHandler(RequestComplete);
    web.OpenReadAsync(new Uri("http://fullurlofyourwebservice.com"));
    

    You can then write a method for the RequestComplete method referenced in the second line of code:

    void RequestComplete(object sender, OpenReadCompletedEventArgs e)
            {
                string response = "";
    
                using (var reader = new StreamReader(e.Result))
                {
                    response = reader.ReadToEnd();
                }
            }
    

    You can then process the response as a simple string, or do something like XDocument.Parse(response) if your response is in XML format.

    Check out the full MSDN documentation for a complete reference.

    0 讨论(0)
  • 2021-01-17 07:48

    I've recently started using RestSharp. http://restsharp.org/

    Small, simple and does what it says on the box.

    0 讨论(0)
提交回复
热议问题