C#向服务器发送XML数据

24 篇文章 0 订阅

winform

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace testHttpRequest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string postData = "<?xml version='1.0'?><data>dsfsd</data>";
            Encoding encoding = Encoding.UTF8;
            byte[] data = encoding.GetBytes(postData);
            System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhost:1260/WebSite2/Default.aspx");
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentType = "text/XML";//SOAP
            req.ContentLength = data.Length;
            System.IO.Stream newStream = req.GetRequestStream();
            //   发送数据  
            newStream.Write(data, 0, data.Length);
            System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
            MessageBox.Show(res.StatusDescription.ToString());
            newStream.Close();  
        }

      
    }
}

http://localhost:1260/WebSite2/Default.aspx

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        doc.Load(Request.InputStream);
        doc.Save(Server.MapPath("a.xml"));  
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值