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"));
}
}