[C#]使用HttpWebRequest请求远端服务器时如何加载SSL证书

C# HttpWebRequest 获取 HTTPS 网页内容 在上述代码中,我们首先设置了 ServicePointManager.ServerCertificateValidationCallback 回调函数,该回调函数会在服务器端的证书被验证的时候被调用,当回调函数返回 true 时,表示服务器端的证书验证通过,否则会抛出一个 SSL 异常。如果服务器端证书的颁发机构是自签署的或不受信任的颁发机构,那么你需要通过比较证书中的公钥和期望值来验证证书的有效性。如果你希望进一步加强服务器端证书的验证,可以通过检查证书的完整性、状态、可用性等等。 阅读详情
编写者:郑昀 @UltraPower

首先加上引用“System.Security.DLL”,其次在工程中

using System.Security.Cryptography.X509Certificates;

这样就可以使用“

X509Certificate Class

”了,它的定义参见http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecuritycryptographyx509certificatesx509certificateclasstopic.asp。

之后我们就可以

///构建请求的HttpWebRequest对象

HttpWebRequest hwrRequest = (HttpWebRequest)WebRequest.Create(

                                   strValidatePageURL);

/// 从本地文件中加载证书

hwrRequest.ClientCertificates.Add(X509Certificate.CreateFromCertFile("c://motor.https.pem.cer"));

这是一个较简单的办法。

如果你遇到了“The underlying connection was closed. Could not establish a secure SSL/TLS connection"”的异常,那么请设置

hwrRequest.KeepAlive = true;

所以,。。。,还是请使用 CreateFromCertFile 好了。

至于如何“在个人证书存储区获取证书”,参看下面的blog:

参看:WSE2.0中X509安全令牌的使用

和 调用web service如何加载证书 .

编写者:郑昀 @UltraPower
20050328

如果您使用的是 CreateFromSignedFile来创建证书,那么请您务必注意,即使CreateFromSignedFile没有能够从文件中创建证书,甚至即使没有找到该文件,他也不会抛出异常,也不返回null,只是他的各个字段为null。
 
c#中https通讯如何添加证书 c#如何在https在通讯中需要添加证书密码 public static class HTTPS { // byte[] certificate = Properties.Resources.client1; //2.定义方法: private static bool RemoteCertificateValidate(object send... 阅读详情

相关推荐

智能车竞赛轮腿穿越组:GPS+IMU导航绕桩实战技巧(附避坑指南)

本文详细介绍了智能车竞赛轮腿穿越组中GPS+IMU导航绕桩的实战技巧,包括硬件选型、传感器标定、路径规划及多传感器数据融合策略。通过实际案例和避坑指南,帮助参赛队伍提升导航精度和稳定性,避免常见错误。特别强调IMU安装位置和标定对导航系统的重要性。

gin88的博客 592

HttpWebRequest获取网页内容

/// <summary> /// 获取请求结果 /// </summary> /// <param name="requestUrl">请求地址</param> /// <param name="timeout">超时时间(秒)</param> /// <param name="requestXML">请求xml内容</param> /// <par

qq_34609385的博客 1210

Redis简介和项目应用

内存优先架构简介Redis的读写操作都是在内存中执行的,计算机内存的读写速度极快,比机械硬盘的读写快很多,因此也会比MySql采用机械读写的方式性能更高。但是这样会产生一个问题,当Redis重启之后,内存中的数据就会丢失,为了保证数据不会因为服务器重启而丢失,Redis实现了数据持久化的机制,这个机制会把数据存储到磁盘中,当服务器重启的时候,能够从磁盘中恢复原有的数据。

人工智能、机器学习 764

C#访问HttpWebRequest和WebService(with SSL)

使用HttpWebRequest请求远端服务器时如何加载SSL证书。webservice的ssl方法太复杂,没验证。http://www.cnblogs.com/fooo/archive/2008/10/31/1323396.htmlC#访问WebService(with SSL)http://xwhoyeah.javaeye.com/blog/101298使用 HttpWebReques

3360

SQL中的时间计算:员工每日工作时长

摘要:本文介绍了一个使用SQL查询计算员工每日工作时长的实用方法。通过分析包含员工打卡记录的数据库表,利用CTE(公共表表达式)将日期分组,计算最早和最晚打卡时间差,最终以"小时:分钟"格式输出工作时长。该方法适用于每日两次打卡的场景,并提示了处理漏打卡等特殊情况时的注意事项,为企业考勤管理提供了有效的数据支持方案。(148字)

m0_74337424的博客 413

ROS从入门到精通0-1:教程导读

ROS概念太多太复杂?ROS从入门到精通系列订阅必看

FRIGIDWINTER的博客 1万+

[C#]用HttpWebRequest加载证书建立SSL通道时发生异常的解决办法

[C#]用HttpWebRequest加载证书建立SSL通道时发生异常的解决办法 Posted on 2005-04-11 22:46 让变化成为计划的一部分 阅读(970) 评论(7)  编辑 收藏 收藏至365Key 所属分类: HttpWebRequest <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-n

Ar7的专栏 5877

基于STM32+4G模块设计的智能灌溉系统

当前智能灌溉系统分为三个部分:温湿度采集部分、灌溉系统部分、OneNet云平台。 灌溉系统部分增加刷卡功能,用户可以通过IC卡刷卡将金额刷到灌溉系统设备里,灌溉系统设备里会记录金额,并且在手机可视化页面上会显示当前的设备金额。 金额会随着时间进行递减,按分钟计费,如果计费到0,就无法启动灌溉,需要重新充值金额才能继续。

4521

[dotNET]使用HttpWebRequest请求远端服务器时如何加载SSL证书

使用HttpWebRequest请求远端服务器时如何加载SSL证书编写者:郑昀@UltraPower 首先加上引用“System.Security.DLL”,其次在工程中using System.Security.Cryptography.X509Certificates;这样就可以使用“X509Certificate Class”了,它的定义参见http://msdn.microsoft.c

软件开发资料汇总 619

基于POD和神经网络的多工况温度场重构反演系统

本文提出了一种基于本征正交分解(POD)和神经网络的多工况温度场重构反演系统。该系统通过POD方法从多工况温度场数据中提取主要特征模态,构建神经网络模型建立工况参数与POD模态系数的映射关系,实现温度场的快速重构。系统采用Python实现,包含数据预处理、POD分解、神经网络训练和温度场重构等模块。实验结果表明,该方法能够有效降低计算复杂度,实现高精度的温度场预测。

huanghm88的专栏 286

(七)独立按键

(七)独立按键

m0_52555663的博客 1741

[dotNET]用HttpWebRequest加载证书建立SSL通道时发生异常的解决办法

用HttpWebRequest加载证书建立SSL通道时发生异常的解决办法 编写者:郑昀@UltraPower关键字:HttpWebRequest,SSL,X509CertificatedotNet  Framwork 1.1编写时间:2005-3-29WSE 2.0 SP3 目的:对于用HttpWebRequest加载证书请求远端https服务器时,发生的“基础连接已经关闭: 无法与远程服务器

.NET博文收藏 1435

论文阅读:arixv 2025 Poisoning Attacks on LLMs Require a Near-constant Number of Poison Samples

研究者做了目前最大规模的“投毒实验”,训练了从6亿参数到130亿参数的模型(覆盖了中小到大型LLM),用的训练数据量也是“最适合模型大小”的(按行业里的“Chinchilla法则”,模型越大,训练数据量也按比例增加)。总结下来就是:这篇论文告诉我们,给大语言模型投毒,比之前想的容易得多——不需要海量毒数据,只要几百条藏好后门的文档,就能让大模型“带毒工作”,而且平时还看不出来。——这比之前大家担心的“需要投毒数据占训练集一定比例”要可怕得多,因为对大模型来说,“固定数量”的毒数据更容易偷偷塞进去。

CSPhD-winston的博客 1089

HttpWebRequest加载证书请求远端https服务器时 : 基础连接已经关闭: 无法与远程服务器建立信任关系...

目的: 对于用HttpWebRequest加载证书请求远端https服务器时,发生的 “基础连接已经关闭: 无法与远程服务器建立信任关系。”/ “The underlying connection was closed. Could not establish a secure SSL/TLS connection”错误,我们可以用如下方式解决。 重现: 使用以下代码,你...

weixin_30548917的博客 304

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

c#获取ssl证书有效性_如何在C#中使用带有HttpWebRequest的SSL证书?

目前我正在编写一个实用程序应用程序,它将连接到给定的IP和端口,并使用HttpWebRequest检查SSL证书中的信息.当我尝试提取证书时,我收到一个错误,即抛出异常.例外似乎是因为应对SSL证书的行为似乎触发了另一个验证检查.这是代码,也许有人可以告诉我一个更好的方法来做这个或如果我错过了什么.我不在乎SSL证书是否已过期或与URL不匹配.这些都与我正在做的事情无关.当我将委托中的X509Ce...

weixin_32816563的博客 1175

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

上一篇: ASP.NET中文件上传下载方法集合
下一篇: 在MSSQL中添加记录后获取当前记录ID的方法
nutian
博客等级 码龄24年 42粉丝 59原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址