博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.net Post XML格式数据
阅读量:5254 次
发布时间:2019-06-14

本文共 1903 字,大约阅读时间需要 6 分钟。

StringBuilder strBuilder = new StringBuilder();

strBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?");
strBuilder.Append("<ROBOT Version=\"2.0\">");
strBuilder.Append("<DiskFreeSpace></DiskFreeSpace>");
strBuilder.Append("<MyFileName>weixin.htm</MyFileName>");
strBuilder.Append("<MyTitle>");
strBuilder.Append(TITLE);
strBuilder.Append("</MyTitle>");
strBuilder.Append("<MyURL>");
strBuilder.Append(URL);
strBuilder.Append("</MyURL>");
strBuilder.Append("<MyMedia>");
strBuilder.Append(MEDIA);
strBuilder.Append("</MyMedia>");
strBuilder.Append("<MyColumn>");
strBuilder.Append(COLUMN);
strBuilder.Append("</MyColumn>");
strBuilder.Append("<MyDownTime>");
strBuilder.Append(PUBLISHTIME);
strBuilder.Append("</MyDownTime>");
strBuilder.Append("<HaveImage>");
strBuilder.Append(0);
strBuilder.Append("</HaveImage>");
strBuilder.Append("<MyInsertTime>");
strBuilder.Append(crawTime);
strBuilder.Append("</MyInsertTime>");
strBuilder.Append("<SumImage>");
strBuilder.Append(0);
strBuilder.Append("</SumImage>");
strBuilder.Append("<MyComputerName>");
strBuilder.Append("WEIXIN-FA");
strBuilder.Append("</MyComputerName>");
strBuilder.Append("</ROBOT>");
string postData = strBuilder.ToString();
var encoding = Encoding.GetEncoding("GBK");
byte[] buffer = encoding.GetBytes(postData);
//创建链接
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webURL);
request.Method = "post";
request.ContentLength = buffer.Length;
request.ContentType = "text/xml";
Stream newStream = request.GetRequestStream();
byte[] Lastdata = Encoding.GetEncoding("GB2312").GetBytes(postData);
newStream.Write(Lastdata, 0, Lastdata.Length);
//开始请求,并得到返回值
HttpWebResponse res = request.GetResponse() as HttpWebResponse;
StreamReader srder = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("GB2312"));
String ret = srder.ReadToEnd();
newStream.Close();

转载于:https://www.cnblogs.com/yyangjing/p/9474250.html

你可能感兴趣的文章