zoukankan      html  css  js  c++  java
  • HttpWebRequest外部服务

    public static string CallService(string strXml)

            {

                Uri uri = new Uri(Settings.SettingWebServiceUrl);

                string postData = strXml;

                string result = null;

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

                request.KeepAlive = true;

                request.Timeout = 60000;

                request.ContentType = "text/xml";

                request.Accept =

                    "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";

                request.Method = "POST";

                byte[] data = Encoding.UTF8.GetBytes(postData);

                request.ContentLength = data.Length;

                try

                {

                    request.ClientCertificates.Add(

                        new X509Certificate2(

                            Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.CertificateFileName),

                            Settings.CertificatePwd));

                    System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

                    if (Settings.IfQC != "true")

                    {

                        WebProxy proxy = new WebProxy();

                        proxy.Address = new Uri(Settings.ProxyUrl);

                        string username = Settings.ProxyUserID;

                        string password = Settings.ProxyPassword;

                        proxy.Credentials = new System.Net.NetworkCredential(username, password);

                        request.Proxy = proxy;

                    }

                    using (Stream writer = request.GetRequestStream())

                    {

                        writer.Write(data, 0, data.Length);

                    }

                    WebResponse response = request.GetResponse();

                    using (Stream responseStream = response.GetResponseStream())

                    {

                        using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))

                        {

                            result = reader.ReadToEnd();

                        }

                    }

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                return result;

            }

  • 相关阅读:
    IntelliJ IDEA 常用快捷键
    solr4.5分组查询、统计功能介绍
    用于Lucene的各中文分词比较
    Lucene打分规则与Similarity模块详解
    Lucene
    tar中的参数 cvf,xvf,cvzf,zxvf的区别
    tmux 入门踩坑记录
    第一个shell脚本
    make 和 make install 的区别
    交叉编译
  • 原文地址:https://www.cnblogs.com/anranstl/p/5241203.html
Copyright © 2011-2022 走看看