做Paypal的支付功能,支付成功后,返回服务端的验证信息,
报错:服务器提交了协议冲突. Section=ResponseStatusLine,怎么解决??
protected void Page_Load(object sender, EventArgs e) { string authToken = "XXXXXX"; string txToken = Request.QueryString["tx"]; string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken; string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; string strLive = "https://www.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox); //公司用代理服务器上网 WebProxy proxy = new WebProxy("XXXXX:XXX", false); proxy.Credentials = new NetworkCredential("XXXXX", "XXXXX"); req.AllowAutoRedirect = false; req.Proxy = proxy;
req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = query.Length; StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(query); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); streamIn.Close(); Dictionary<string, string> results = new Dictionary<string, string>(); if (strResponse != "") { StringReader reader = new StringReader(strResponse); string line = reader.ReadLine();
//支付成功后进行状态修改 if (line == "SUCCESS") { UserOrder order = UserOrderDAL.m_UserOrderDAL.GetModel(string.Format("OrderCode='{0}'", txToken)); order.IsPay = 1; order.Status = 2; UserOrderDAL.m_UserOrderDAL.Update(order); Response.Write(string.Format("Order Number:{0} Pay for success. The total amount of:{1}", txToken, order.SubPrice + 5)); } else if (line == "FAIL") { Response.Write("Order payment failure"); } } else { Response.Write("ERROR"); } }
报错:
网上查了,大多数是说要在Web.config里面添加
<system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true" /> </settings> </system.net>
测试后,无效!