TLS 1.2 httpwebrequest无法正常工作

时间:2017-08-21 08:13:31

标签: ssl

我有3d安全支付系统 我想使用HttpWebQuest发送数据并绘制结果。 幸运数据尚未到货。你需要通过tls 1.2到达。我在哪里犯错误?你能帮忙吗?

示例代码;

  System.Net.HttpWebResponse resp = null;
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
                System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(apiUrl);
                string postdata = "DATA=" + xmlval.ToString();
                byte[] postdatabytes = System.Text.Encoding.GetEncoding("ISO-8859-9").GetBytes(postdata);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = postdatabytes.Length;
                System.IO.Stream requeststream = request.GetRequestStream();
                requeststream.Write(postdatabytes, 0, postdatabytes.Length);
                requeststream.Close();
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
                resp = (System.Net.HttpWebResponse)request.GetResponse();
                System.IO.StreamReader responsereader = new System.IO.StreamReader(resp.GetResponseStream(), System.Text.Encoding.GetEncoding("ISO-8859-9"));

                string responseXML = responsereader.ReadToEnd(); //Response read as XML string

                System.Xml.XmlDocument response = new System.Xml.XmlDocument();
                response.LoadXml(responseXML);    //string parsed as XML document

                System.Xml.XmlNodeList list = response.GetElementsByTagName("Response");
                ltrResponse.Text = list[0].InnerText;

                list = response.GetElementsByTagName("AuthCode");
                ltrAuthCode.Text = list[0].InnerText;

                list = response.GetElementsByTagName("HostRefNum");
                ltrHostRefNum.Text = list[0].InnerText;

                list = response.GetElementsByTagName("ProcReturnCode");
                ltrProcReturnCode.Text = list[0].InnerText;

                list = response.GetElementsByTagName("TransId");
                ltrTransId.Text = list[0].InnerText;

                list = response.GetElementsByTagName("ErrMsg");
                ltrErrMsg.Text = list[0].InnerText;

                if (ltrProcReturnCode.Text == "99")
                {
                    lblPaymentResult.Text = "Ödeme Başarısız.";
                    lblPaymentResult.ForeColor = System.Drawing.Color.Red;
                }
                else if (ltrProcReturnCode.Text == "00")
                {
                    lblPaymentResult.Text = "Ödeme Başarılı";
                    lblPaymentResult.ForeColor = System.Drawing.Color.Green;
                }
            }
            catch (Exception ex)
            {
                lblPaymentResult.Text = "Bir Hata Oluştu : " + ex.ToString() + "";
                lblPaymentResult.ForeColor = System.Drawing.Color.Red;
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
            }
        }
        else
        {
            lblPaymentResult.Text = "3D Kimlik Doğrulaması Başarısız. Ödeme İsteği Gönderilemedi !";
            lblPaymentResult.ForeColor = System.Drawing.Color.Red;
        }
    }

0 个答案:

没有答案