如何使用Windows Phone应用程序调用PHP文件?

时间:2012-06-25 09:34:35

标签: windows-phone-7 windows-phone-7.1

我想在WP7应用程序中使用远程MySQL数据库创建一个简单的登录功能,使用PHP作为后端。我从来没有在C#中使用它,所以我不知道该怎么做。

1 个答案:

答案 0 :(得分:2)

您可以使用WebClientHttpWebRequest类发出网络请求并获得回复。

以下是有关如何发出请求并获得回复的示例代码

WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://someurl", UriKind.Absolute));

异步响应处理程序在这里

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    var response= e.Result; // Response obtained from the web service  
}

以上示例适用于任何Web服务(可能是 PHP 或jsp或asp等)。

您需要做的就是提出正确的请求并处理回复