在我的项目中,我想编写一个桌面应用程序,该应用程序以文件或字符串的形式发送xml文档,
到需要解析它的服务器上的php脚本.
现在,我有解析xml的php脚本,并已在桌面应用程序中准备好了xml.
我的问题是:
一种.哪种方法更好:将文档作为文件或字符串发送?
b.如何通过C#实现请求(文件或字符串),以及如何通过php接受文档.
笔记:
一种.我只能在桌面应用程序上使用C#.
b.我只能在服务器上使用php脚本.
C.我使用System.xml.linq在桌面应用程序中处理xml文档.
非常感谢!
解决方法:
您可以根据自己的喜好简单或复杂;-)
这是一个非常简单的基本示例(没有错误处理等):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Net;
namespace LinqXMLTest
{
class Program
{
static void Main(string[] args)
{
Object[] res = { "Stackoverflow", true, 'x', 42};
XElement xml = new XElement("Foo",
from a in res select
new XElement("bar",
new XElement("type", a.GetType()),
new XElement("value", a.ToString())
)
);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/test.php");
request.Method = "POST";
xml.Save( request.GetRequestStream() );
HttpWebResponse resp = request.GetResponse() as HttpWebResponse;
}
}
}
并作为“接收者”:
$fp = fopen('php://input', 'rb');
file_put_contents('test.dat', $fp);
之后服务器上的文件test.dat包含
System.String
Stackoverflow
System.Boolean
True
System.Char
x
System.Int32
42
标签:desktop-application,xml,c,net,php
来源: https://codeday.me/bug/20191208/2088730.html