HttpClient and HttpGet Support in WP7

心已入冬 提交于 2019-12-30 14:44:45

问题


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 Webservice URL. The code uses HttpClient and HttpGet for GET,POST,PUT & DELETE operation in Android . Can anyone guide me where to start with as I am new to this Platform.


回答1:


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.




回答2:


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




回答3:


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

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



来源:https://stackoverflow.com/questions/10444273/httpclient-and-httpget-support-in-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!