.net2005和2003下进行https请求的不同实现
2007-03-06 14:39
465 查看
// 2005 下 Frame2.0
private void MainCert()
{
//使用https 时,可免证书合法性
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
}
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // Always accept
return true;
}
//2003 下 frame 1.1
private void MainCert()
{
//使用https 时,可免证书合法性
// System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); }
internal class TrustAllCertificatePolicy: ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
}
public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb)
{
// Always accept
return true;
}
}
别望了引namespace:
using System.Net;
using System.IO;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://someurl");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
Page.Response.Write(readStream.ReadToEnd());
response.Close();
readStream.Close();
private void MainCert()
{
//使用https 时,可免证书合法性
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
}
public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // Always accept
return true;
}
//2003 下 frame 1.1
private void MainCert()
{
//使用https 时,可免证书合法性
// System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy(); }
internal class TrustAllCertificatePolicy: ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
}
public bool CheckValidationResult(ServicePoint sPoint, System.Security.Cryptography.X509Certificates.X509Certificate cert, WebRequest wRequest, int certProb)
{
// Always accept
return true;
}
}
别望了引namespace:
using System.Net;
using System.IO;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://someurl");
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
Page.Response.Write(readStream.ReadToEnd());
response.Close();
readStream.Close();
相关文章推荐
- 1.1和2.0下进行https请求的不同实现
- 1.1和2.0下进行https请求的不同实现
- 第六课 自己实现路由改进,针对不同请求的路径进行响应
- 使用Charles对Https请求进行抓包
- [置顶] iOS使用自签名证书实现HTTPS请求
- C#在一台客户端进行了某个操作以后如何让其他不同的客户端如何实现相同的操作(二)
- JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
- 借助script进行Http跨域请求:JSONP实现原理及代码
- JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
- react native 使用fetch进行网络请求(https),解决SSLHandshake问题,以及怎样进行二次封装
- nginx不同端口映射到80端口,http和https同时请求
- 利用Fiddler对Android https请求进行监测
- 封装UniversalImageLoader框架实现一行代码即可加载图片,且完美支持https图片请求
- 【前端知识点】前后端关于post请求中,对body的不同数据格式的解决处理方案实现
- JAVA利用HttpClient进行POST请求(HTTPS)
- 多个按键绑定同一个监听器,并实现按下,弹起进行不同操作
- Struts2 如何实现同一个action不同方法进行传值
- 如果现在是进行了 http 访问,则应该让请求跳转到 https 的 443 端口上的程序处理类
- 0157 JAVA利用HttpClient进行POST请求(HTTPS)
- HttpsURLConnection实现SSL的GET/POST请求