我需要向服务器发送请求,将如下的 xml 数据附加到服务器的 url
<User>
<MobileNumber>xxxxxxxxxx</MobileNumber>
<UserAgent>yyyyy</UserAgent>
</User>
我会得到如下回复
<User>
<MobileNumber>xxxxxxxxxx</MobileNumber>
<ModelId>zzzzzz</ModelId>
<AuthKey>aaaaaaaaa</AuthKey>
<UserAgent>yyyyy</UserAgent>
</User>
我想解析收到的 xml 数据 在 Windows Phone(7) 中执行此操作的正确方法是什么?首先用 xml 请求 url,然后接收 xml 我是 windows phone 开发的新手,应该使用什么类?
我很困惑 - WebClient WebRequest WebResponse HttpWebRequest HttpWebResponse
编辑:我尝试使用以下代码发送请求,如何接收响应?
private void Upload()
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
var uri = new Uri("xxxxxxxxxx", UriKind.Absolute);
StringBuilder postData = new StringBuilder();
postData.AppendFormat("{0}={1}", "MobileNumber", HttpUtility.UrlEncode("yyyyyyyyy"));
postData.AppendFormat("&{0}={1}", "UserAgent", HttpUtility.UrlEncode("WP7"));
webClient.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();
webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(webClient_UploadStringCompleted);
webClient.UploadProgressChanged += webClient_UploadProgressChanged;
webClient.UploadStringAsync(uri, "POST", postData.ToString());
}