-1

我在window7 手机中有一个注册表单,我想用C# 调用一个PHP 页面,以便我在表单中插入的值必须保存到服务器。我怎样才能做到这一点?

4

2 回答 2

1

您可以使用WebClient允许您向远程端点发送 HTTP 请求的类。

这是一个例子:

WebClient wc = new WebClient();
wc.OpenReadCompleted += OpenReadCompleted;
UriBuilder fullUri = new UriBuilder("http://example.com/foo.php");
wc.OpenReadAsync(fullUri.Uri);

然后您将拥有OpenReadCompleted请求成功时将调用的处理程序:

void OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    using (Stream responseStream = e.Result)
    using (StreamReader reader = new StreamReader(responseStream))
    {
        string response = reader.ReadToEnd();
        // do something with the response
    }
}
于 2013-01-14T06:43:08.777 回答
0

首先,您不能在 C# 中创建 PHP 页面。PHP 与 C# 完全不同。

您可能想要的是您的手机应用程序可以调用的 Web 服务。Web 服务很容易从 .NET 应用程序(包括电话应用程序)创建和使用。

这是一篇您可能会发现有用的介绍性文章:http: //a1ashiish-csharp.blogspot.com/2012/01/cnet-how-to-create-web-service-in-cnet.html

这是一篇关于从 Windows Phone 7 应用程序使用 Web 服务的文章:http: //www.codeproject.com/Questions/355937/How-to-use-webservice-in-Windows-Phone-7-applicati

还有一个:http ://code.msdn.microsoft.com/wpapps/Weather-Forecast-Sample-586ef733

祝你好运!

于 2013-01-14T12:45:08.677 回答