C# HttpRequest的一些记录总结

来源:互联网 发布:java http代理服务器 编辑:程序博客网 时间:2024/05/21 22:29
做接口的过程中,在没有修改代码的情况下,WCF突然不可用。报错为:System.Net.WebException: 基础连接已经关闭: 发送时发生错误。 
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

返回的resp为NULL,郁闷了好久。。

网上查阅资料,说法非常多: 大概为这些。

   ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

   ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
   request.ProtocolVersion = HttpVersion.Version10;
  ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);

  查阅资料发现,大多跟安全协议有关。环境为.NET4.0。询问得知, HTTP请求的网页,采用SSL Protocol:TLS v1.2,

  我的代码为:

  System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

  不满足此安全协议。查阅资料,得到:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

经本机环境测试,可以。。待客户环境测试后,看效果。。。再来更新。。


然而,客户那继续报错。。。

(一)

连接WCF时出现如下错误信息:
The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

由于内部错误,无法处理请求。


处理办法:

        <behavior>          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->          <serviceDebug includeExceptionDetailInFaults="true"/>        </behavior>


(二)the requested security protocol is not supported

不支持此种安全协议。。客户装的.NET 4.0 。。所以,服务器不支持。。。怎么办?






原创粉丝点击