有没有可能用PHP连接.NET应用程序?我的意思是,PHP将返回XML或JSON文件到.NET,如果数据是XML,.NET将使用LINQ。如果可能的话,我该怎么做呢?
有什么例子吗?
发布于 2012-06-18 00:25:50
您可以创建一个返回JSON/ XML的PHP应用程序。然后,在您的.NET应用程序中,您可以访问它(与访问webservices/REST服务的方式相同)。您可以使用HttpWebRequest类来访问服务,如下所示。
string restURL="www.yoursite.com/yourphpwebservice.php";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(restURL);
request.Method = "GET";
request.Accept = "text/xml";
request.ContentType = "text/xml";
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
using (WebResponse response2 = request.GetResponse())
using (Stream stream = response2.GetResponseStream())
{
XElement myXel = XElement.Load(stream);
if (myXel != null)
{
//now you can access the XML elements with LINQtoXML
}
}
}发布于 2012-06-18 00:19:04
如果要通过PHP返回XML文件,则可以使用.NET XDocument类:
XDocument xdoc = XDocument.Load("data.xml");
var query = from xml in xdoc.Descendants("node")
select new {
Attribute1 = lv1.Attribute("Attribute1").Value,
Attribute2 = lvl1.Attribute("Attribute2").Value
};http://msdn.microsoft.com/en-us/library/bb299195
https://stackoverflow.com/questions/11072822
复制相似问题