生产服务器

时间:2017-07-05 08:27:01

标签: c# http ssl httpwebrequest

在我的应用程序部署到生产服务器时遇到此错误,而在我的本地计算机上运行良好

  

System.Net.WebException:底层连接已关闭:An   意外的呃       或发生在发送上。 ---> System.IO.IOException:身份验证失败,因为        远程方已关闭传输流。          在System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readByte       ,AsyncProtocolRequest asyncRequest)          在System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtoco       请求asyncRequest)          在System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolTok       n消息,AsyncProtocolRequest asyncRequest)          在System.Net.Security.SslState.StartSendBlob(字节[]传入,Int32计数,       syncProtocolRequest asyncRequest)          在System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst,          在zz.Program.Main(String [] args)

这部分代码

   string MsgType = "cmpi_authenticate";
    string Version = "1.7";
    XElement elem = new XElement("CardinalMPI",
        new XElement("MsgType", MsgType),
        new XElement("Version", Version),
        new XElement("ProcessorId", ProcessorId),
        new XElement("MerchantId", MerchantId),
        new XElement("TransactionPwd", TransactionPwd),
        new XElement("TransactionType", TransactionType),
        new XElement("TransactionId", TransactionId),
        new XElement("PAResPayload", PAResPayload)
       );

    StringBuilder postData = new StringBuilder();
    postData.Append("cmpi_msg=" + HttpUtility.UrlEncode(elem.ToString()));

    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] data = encoding.GetBytes(postData.ToString());
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.Timeout = 30 * 1000;
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;
    Stream newStream = request.GetRequestStream();
    newStream.Write(data, 0, data.Length);
    //newStream.Flush();
    //newStream.Close();
    //request.KeepAlive = false;

    string resText = "";
    //ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    //**this is the point of failure**
    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        Encoding enc = System.Text.Encoding.GetEncoding(1252);
        using (StreamReader rs = new StreamReader(response.GetResponseStream(), enc))
        {
            resText = rs.ReadToEnd();
            //Console.WriteLine("RES:" + resText);
        }
    }

0 个答案:

没有答案