• C# WebService服务Post提交


    public string WebServerTest(string PostData)
            {
                PostData = "jsonData=" + PostData;
                string POSTURL = "http://101.201.78.100:8888/ChannelWebService.asmx/CheckIsConnected";
                Encoding myEncoding = Encoding.GetEncoding("UTF-8"); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; //将提交的字符串数据转换成字节数组 //注意提交的编码,这里默认的是Default:系统当前编码 
                byte[] postData = myEncoding.GetBytes(PostData); //设置提交的相关参数 
                HttpWebRequest request = WebRequest.Create(POSTURL) as HttpWebRequest; //实例化一个证书 
                //X509Certificate2 cerCaiShang = GetCertificate(); ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; 
                //request.ClientCertificates.Add(cerCaiShang); 
                request.Method = "POST"; request.KeepAlive = true;
                //request.AllowAutoRedirect = true;
                request.ProtocolVersion = HttpVersion.Version10;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
                request.ContentType = "text/xml;charset=utf-8";
                request.ContentType = "application/x-www-form-urlencoded";
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
                CookieContainer cookieContainer = new CookieContainer();
                request.CookieContainer = cookieContainer;
                request.ContentLength = postData.Length;
                #region 传输数据
                try { using (Stream writer = request.GetRequestStream()) { writer.Write(postData, 0, postData.Length); } }
                catch (Exception ex) { return ex.Message; }
                #endregion
                #region 接收返回的数据
                string srcString = string.Empty; try { HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream sr = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(sr, myEncoding)) { srcString = reader.ReadToEnd(); } } }
                catch (Exception ex) { return ex.Message; }
                #endregion
                return srcString;
            }
    

      

  • 相关阅读:
    买点
    正则
    burp回放
    py打包问题
    运行elementUI相关组件的时候的问题
    客户端性能(转载)
    客户端性能(转载)
    关于Appium android input manager for Unicode 提示信息
    selenium 分布式 [WinError 10061] 由于目标计算机积极拒绝
    WPF数据绑定-依赖属性
  • 原文地址:https://www.cnblogs.com/XuPengLB/p/6025290.html
Copyright © 2020-2023  润新知