首页 > 其他 > 详细

发送xml数据给服务器

时间:2015-12-03 13:56:44      阅读:269      评论:0      收藏:0      [点我收藏+]

后台通过context.Request.InputStream来接收

#region 发送消息 + void SendMessage()
/// <summary>
/// 发送消息
/// </summary>
public void SendMessage()
{
//CurrentContext.Response.Write("Hello F1");
string lbSourceUrl = CurrentContext.Request["lbSourceUrl"];
string textMessage = CurrentContext.Request["textMessage"];

byte[] entity = Encoding.UTF8.GetBytes(textMessage);
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(lbSourceUrl));
httpReq.AllowAutoRedirect = true;
httpReq.KeepAlive = true;
httpReq.Method = "POST";
httpReq.ContentType = "text/xml; charset=UTF-8";
httpReq.ContentLength = entity.Length;

Stream reqStream = httpReq.GetRequestStream();
reqStream.Write(entity, 0, entity.Length);
reqStream.Close();

HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();

StreamReader respStream = new StreamReader(httpResp.GetResponseStream(), Encoding.UTF8);
string result = respStream.ReadToEnd();

respStream.Close();
httpReq.Abort();
httpResp.Close();

CurrentContext.Response.Write(result);
}
#endregion

发送xml数据给服务器

原文:http://www.cnblogs.com/james641/p/5015777.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!