以post方式发送文档到端口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml;
using System.Net;
using System.IO;

namespace WindowsFormService
{
public class HttpSend
{

public XDocument sendXmlAndGetResponse(XDocument xDocument)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xDocument.Document.ToString());
WebResponse resp;
string strUrl = XMLTools.getXmlValue("LFListenerAddress", "Address");// "http://localhost:8008/hello/";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.ContentType = "text/xml";
myRequest.Method = "POST";
Stream stm = myRequest.GetRequestStream();
doc.Save(stm);
stm.Close();
resp = myRequest.GetResponse();
stm = resp.GetResponseStream();
//StreamReader r = new StreamReader(stm);
//MessageBox.Show(r.ReadToEnd().ToString(), "MESSAGE ");

var reDoc = new XmlDocument();
reDoc.Load(stm);

return reDoc.ToXDocument();
}
}
}

posted @ 2012-01-13 17:21  cotty  阅读(362)  评论(0编辑  收藏  举报