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;

            }

  • 相关阅读:
    查看python中已安装的包有哪些
    error: pathspec 'master' did not match any file(s) known to git.
    【RF库Collections测试】lists should be equal
    Robot Framework配置发送邮件功能
    【转载】浅谈TDD、BDD与ATDD软件开发
    Json转换工具类(基于google的Gson和阿里的fastjson)
    Solr系列三:solr索引详解(Schema介绍、字段定义详解、Schema API 介绍)
    Solr系列二:solr-部署详解(solr两种部署模式介绍、独立服务器模式详解、SolrCloud分布式集群模式详解)
    Solr系列一:Solr(Solr介绍、Solr应用架构、Solr安装使用)
    Lucene系列六:Lucene搜索详解(Lucene搜索流程详解、搜索核心API详解、基本查询详解、QueryParser详解)
  • 原文地址:https://www.cnblogs.com/anranstl/p/5241203.html
Copyright © 2011-2022 走看看