WP7 中的 HttpClient 和 HttpGet 支持 [英] HttpClient and HttpGet Support in WP7
问题描述
我正在构建一个已经在 Android 中构建的应用程序其他移动平台.由于该应用程序使用在 JAVA 中构建的基于 REST 的 Webservices,因此我需要使用这些 Webservice URL.代码使用 HttpClient 和 HttpGet 进行 GET、POST、PUT &Android 中的 DELETE 操作.任何人都可以指导我从哪里开始,因为我是这个平台的新手.
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.
推荐答案
我建议使用 WebClient 类进行基于 HTTP 的简单通信.以下是我向 Web 服务发出请求时通常使用的基本格式:
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"));
然后您可以为第二行代码中引用的 RequestComplete 方法编写一个方法:
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();
}
}
然后您可以将响应作为一个简单的字符串进行处理,或者如果您的响应是 XML 格式,则执行类似 XDocument.Parse(response)
的操作.
You can then process the response as a simple string, or do something like XDocument.Parse(response)
if your response is in XML format.
查看完整的MSDN 文档以获取完整参考.
Check out the full MSDN documentation for a complete reference.
这篇关于WP7 中的 HttpClient 和 HttpGet 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!