赞
踩
- public String Get(string url, byte[] data)
- {
-
- HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
- try
- {
- //服务器需安装.net4.5,否则报错:The requested security protocol is not supported. (不支持请求的安全协议)
- ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
- //SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11
- //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
- ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
-
- req.ProtocolVersion = HttpVersion.Version11;
- req.Method = "POST";
- req.KeepAlive = false;
- //req.Timeout = 1200000;
- req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
- //req.Headers.Add("ContentType", "application/x-www-form-urlencoded");
- req.Headers.Add("appKey", appKey);
- req.Headers.Add("appSecret", appSecret);
- req.ContentLength = data.Length;
- using (Stream reqStream = req.GetRequestStream())
- {
- reqStream.Write(data, 0, data.Length);
- }
- using (WebResponse response = req.GetResponse())
- {
- string text = "";
- using (Stream responseStm = response.GetResponseStream())
- {
- StreamReader redStm = new StreamReader(responseStm, Encoding.UTF8);
- text = redStm.ReadToEnd();
- }
- response.Close();
- //response = null;
- req.Abort();
- return text;
- }
- }
- catch (Exception ex)
- {
- if (ex.InnerException != null)
- {
- HttpContext.Current.Response.Write("内部错误信息:" + ex.InnerException.Message + "<br>");
- }
- req.Abort();
- throw ex;
- }
- return string.Empty;
- }

错误1:The requested security protocol is not supported. (不支持请求的安全协议)
原因:因为服务器上需安装.net4.5,(如果无效可以尝试重装IIS)
错误2:The remote name could not be resolved: 'nginx.platform.xxxxxx.cn'
原因:服务器无法解析这个域名,需要配置DNS解析
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。