• 大小: 38.74MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-22
  • 语言: 其他
  • 标签: xml  

资源简介

采用httpclient发送xml报文,httpServer接收报文。两个程序一看就明白可以直接调用执行不在多说。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Web;

namespace testhttp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            string targetURL = “http://localhost:22885/Home/getdate“;

            string param = Buildxml();
            PostAndGetHTML(targetURL param);
        }
        private string Buildxml()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(“l version=\“1.0\“?>“);
            sb.Append(““);
            sb.AppendFormat(“tle>{0}“ “公告标题“);
            sb.Append(“
tle>“);
            sb.AppendFormat(“{0}“ “公告内容,base64加密的“);
            sb.Append(“
“);

            sb.Append(““);

            sb.Append(“
“);
            return sb.ToString();
        }
        public void  PostAndGetHTML(string targetURL string param)
        {

            //formData用于保存提交的信息
            string formData = HttpUtility.UrlEncode(param);

            formData = “strxml=“ + formData;
            //把提交的信息转码(post提交必须转码)
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(formData);



            //开始创建请求
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetURL);
            request.Method = “POST“;    //提交方式:post
            request.ContentType = “application/x-www-form-urlencoded“;
            request.ContentLength = data.Length;



            Stream newStream = request.GetRequestStream();
            newStream.Write(data 0 data.Length);//将请求的信息写入request
            newStream.Close();
            string result = ““;
            using (var res = request.GetResponse() as HttpWebResponse)
            {
                if (res.StatusCode == HttpStatusCode.OK)
                {
                    StreamReader reader = new StreamReader(res.GetResponseStream() Encoding.UTF8);
                    result = reader.ReadToEnd();
                }
            }
            
            //try

            //{
            //    //向服务器发送请求
            //    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            //    Stream s = response.GetResponseStream();
            //    StreamReader sr = new StreamReader(s Encoding.GetEncoding(“utf-8“));
            //    string strResult = sr.ReadToEnd();

            //}
            //catch
            //{
            //}

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      85883  2019-03-28 12:04  WebService\.vs\config\applicationhost.config

    ..A..H.     14848  2019-03-28 12:05  WebService\.vs\WebService\v14\.suo

     文件     145532  2019-03-28 12:05  WebService\packages\Antlr.3.4.1.9004\Antlr.3.4.1.9004.nupkg

     文件     102912  2013-02-22 08:43  WebService\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll

     文件     431616  2013-02-22 08:43  WebService\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.pdb

     文件     121137  2019-03-28 12:04  WebService\packages\bootstrap.3.0.0\bootstrap.3.0.0.nupkg

     文件     120502  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\Content\bootstrap.css

     文件      97949  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\Content\bootstrap.min.css

     文件      14079  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\fonts\glyphicons-halflings-regular.eot

     文件      63157  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\fonts\glyphicons-halflings-regular.svg

     文件      29512  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\fonts\glyphicons-halflings-regular.ttf

     文件      16448  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\fonts\glyphicons-halflings-regular.woff

     文件      59250  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\scripts\bootstrap.js

     文件      28518  2013-09-13 16:05  WebService\packages\bootstrap.3.0.0\content\scripts\bootstrap.min.js

     文件        209  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\content\App.config.transform

     文件        209  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\content\Web.config.transform

     文件    4255648  2019-03-28 12:05  WebService\packages\Entityframework.6.1.3\Entityframework.6.1.3.nupkg

     文件    4976848  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\Entityframework.dll

     文件     601808  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\Entityframework.SqlServer.dll

     文件     145441  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\Entityframework.SqlServer.xml

     文件    3229543  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\Entityframework.xml

     文件     326352  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\zh-Hans\Entityframework.resources.dll

     文件      19664  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\zh-Hans\Entityframework.SqlServer.resources.dll

     文件     172253  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\zh-Hans\Entityframework.SqlServer.xml

     文件    2576741  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net40\zh-Hans\Entityframework.xml

     文件    5196496  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net45\Entityframework.dll

     文件     621264  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net45\Entityframework.SqlServer.dll

     文件     154866  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net45\Entityframework.SqlServer.xml

     文件    3652961  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net45\Entityframework.xml

     文件     326352  2015-03-02 09:32  WebService\packages\Entityframework.6.1.3\lib\net45\zh-Hans\Entityframework.resources.dll

............此处省略973个文件信息

评论

共有 条评论