c#做桌面与php对接,如何将C#桌面应用程序中的xml发送到php服务器脚本并进行解析?...

在我的项目中,我想编写一个桌面应用程序,该应用程序以文件或字符串的形式发送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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值