我正在尝试找到一种方法来在请求Https资源时忽略证书检查,到目前为止,我在互联网上找到了一些有用的文章.
但我还是有一些问题.请查看我的代码.我只是不明白代码ServicePointManager.ServerCertificateValidationCallback是什么意思.
何时调用此委托方法?还有一个问题,我应该在哪个地方编写这段代码?在ServicePointManager.ServerCertificateValidationCallback执行之前还是之前Stream stream = request.GetRequestStream()?
public HttpWebRequest GetRequest()
{
CookieContainer cookieContainer = new CookieContainer();
// Create a request to the server
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_remoteUrl);
#region Set request parameters
request.Method = _context.Request.HttpMethod;
request.UserAgent = _context.Request.UserAgent;
request.KeepAlive = true;
request.CookieContainer = cookieContainer;
request.PreAuthenticate = true;
request.AllowAutoRedirect = false;
#endregion
// For POST, write the post data extracted from the incoming request
if (request.Method == "POST")
{
Stream clientStream = _context.Request.InputStream;
request.ContentType = _context.Request.ContentType;
request.ContentLength …Run Code Online (Sandbox Code Playgroud)