关于win8 metro应用开发 实现登录功能的问题

doris199363 2014-03-03 11:16:47
我的Metro客户端post用户名和密码到服务器端的代码如下:
private async void  Button_Click_1(object sender, RoutedEventArgs e)
{
//Create an Http client and set the headers we want
Uri theUri = new Uri("http://localhost/login.php");
HttpClient aClient = new HttpClient();
aClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
aClient.DefaultRequestHeaders.Add("X-ZUMO-INSTALLATION-ID", "8bc6aea9-864a-44fc-9b4b-87ec64e123bd");
aClient.DefaultRequestHeaders.Add("X-ZUMO-APPLICATION", "OabcWgaGVdIXpqwbMTdBQcxyrOpeXa20");
aClient.DefaultRequestHeaders.Host = theUri.Host;
LIUser User = new LIUser();
User.Uname = username.Text.ToString();
User.psw = psw.Password.ToString();

//Create a Json Serializer for our type
DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(typeof(LIUser));

// use the serializer to write the object to a MemoryStream
MemoryStream ms = new MemoryStream();
jsonSer.WriteObject(ms, User);
ms.Position = 0;

//use a Stream reader to construct the StringContent (Json)
StreamReader sr = new StreamReader(ms);
StringContent theContent = new StringContent(sr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json");

//Post the data
HttpResponseMessage aResponse = await aClient.PostAsync(theUri, theContent);
string responseBody = await aResponse.Content.ReadAsStringAsync();
if (responseBody == "OK")
{
Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("登录成功");
await dialog.ShowAsync();
}
else
{
Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("用户名或密码错误!请重新输入");
await dialog.ShowAsync();
}


}

请大家帮我看看以上代码能不能成功post数据到服务器端,另外服务器端的PHP代码又该怎么写来接收并解析登录信息?
...全文
250 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,136

社区成员

发帖
与我相关
我的任务
社区描述
Windows客户端使用相关问题交流社区
社区管理员
  • Windows客户端使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧