HTTPS与WEBREQUEST的问题

问题描述

部分代码如下:DimhwqAsHttpWebRequesthwq=HttpWebRequest.Create("https://passport.baidu.com/?reg")hwq.Method="POST"hwq.UserAgent="Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.2;.NETCLR1.1.4322)"hwq.ContentType="application/x-www-form-urlencoded"hwq.Accept="*/*"hwq.CookieContainer=NewCookieContainerhwq.CookieContainer.Add(Me.BaiduCookie)hwq.KeepAlive=True'登陆数据DimstrPostDataAsStringDimbuffer()AsByteDimpoststreamAsStream'要发送的数据strPostData="tpl="strPostData=strPostData+"&tpl_ok="strPostData=strPostData+"&skip_ok="strPostData=strPostData+"&aid="strPostData=strPostData+"&need_pay="strPostData=strPostData+"&need_coin="strPostData=strPostData+"&pay_method="strPostData=strPostData+"&u=./"strPostData=strPostData+"&next_target="strPostData=strPostData+"&return_method=get"strPostData=strPostData+"&friend="strPostData=strPostData+"&uid="strPostData=strPostData+"&rand="strPostData=strPostData+"&nick="strPostData=strPostData+"&crypt="+Me.CryptStringstrPostData=strPostData+"&"+Me.CryptString2Name+"="+Me.CryptString2ValuestrPostData=strPostData+"&regin=0"strPostData=strPostData+"&username="+CStr(username)strPostData=strPostData+"&loginpass="+userpass'密码默认为123456strPostData=strPostData+"&verifypass="+userpass'密码默认为123456strPostData=strPostData+"&sex=1"strPostData=strPostData+"&email="+CStr(username)+"@163.com"strPostData=strPostData+"&verifypass=123456"strPostData=strPostData+"&verifycode="+Me.TextBox1.Textbuffer=Encoding.Default.GetBytes(strPostData.ToCharArray)hwq.ContentLength=buffer.Lengthpoststream=hwq.GetRequestStreampoststream.Write(buffer,0,buffer.Length)poststream.Flush()poststream.Close()DimsrAsNewIO.StreamReader(hwq.GetResponse.GetResponseStream,System.Text.Encoding.Default)——————————————————————————————————————————————————————————————————————————PrivateFunctionGetSSL(ByValsenderAsObject,ByValcertificateAsSystem.Security.Cryptography.X509Certificates.X509Certificate,ByValchainAsSystem.Security.Cryptography.X509Certificates.X509Chain,ByValsslPolicyerrorsAsSslPolicyErrors)AsBooleanCType(sender,HttpWebRequest).ClientCertificates.Add(certificate)ReturnTrueEndFunction当运行到hwq.GetResponse.GetResponseStream时程序出错,报错说“连接已关闭”我已经按照网络上的说法针对HTTPS做了改动了阿。

解决方案

解决方案二:
来个vb的高手解决下。。人都走光了
解决方案三:
漏了一段DimServerCertificateValidationCallbackAsNewRemoteCertificateValidationCallback(AddressOfGetSSL)ServicePointManager.ServerCertificateValidationCallback=ServerCertificateValidationCallback这段在刚才的代码前面
解决方案四:
顶起没人知道么
解决方案五:
使用System.Net.Security.SslStream而非httpwebrequest
解决方案六:
楼上能说的更具体些么新年快乐阿!
解决方案七:
大年初一顶起来!
解决方案八:
大年初一顶起来!
解决方案九:
happy牛year
解决方案十:
System.Net.Security.SslStreamMSDN上有的
解决方案十一:
happy牛yearding
解决方案十二:
SSLStream不是问题所在阿而且SSLStream要求流可读可写。这个流是只能写不能读阿
解决方案十三:
引用9楼liujiayu10的回复:

System.Net.Security.SslStreamMSDN上有的

.
解决方案十四:
再次顶起来
解决方案十五:
有个地方我补充一下我用webresponse拿下来的cookies与嗅探器拿下来的不同:以下是webresponse的结果BAIDUID=B9FC355F9D82BFDFCD41B018D229253C:FG=1;expires=Sun,12-Nov-2302:02:43GMT;path=/;domain=.baidu.com,BAIDUID=B9FC355F9D82BFDF277E935D247C5074:FG=1;expires=Sun,12-Nov-2302:02:43GMT;path=/;domain=.baidu.com,BDUSS=lRGOGZxUndTd2FvNjR3b1NaSUt3LU5PRVd1MmRmNXZDfnBaWFBxb2t0UzRzcXBKQkFBQUFBJCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALglg0m4JYNJM;path=/;domain=.baidu.com以下是嗅探器的结果BDUSS=ENxNEVKNVBBOFpzWmFtdzZ5c3Jra2tFcWM4U21mZUhlcXl4d3Nrb1EyNUxyNnBKQmdBQUFBJCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEsig0lLIoNJc;BAIDUID=805A6C7B9EBDABA31FF12913D4CB0098:FG=1;BDSTAT=8b67cd41801d9edc0a7b02087bf40ad162d9f2d3562c11dfa9ec8a1362272c07嗅探器里多了一个BDSTAT,而webresponse里的BAIDUID莫名奇妙的有两个这会不会是问题所在呢
解决方案:
我用工具检测端口数据,还注意到:相差无几的表单数据(大约300多Bytes),用IE提交时,发送到BAIDU服务器的数据有大约2000Bytes左右而如果用WebRequest的RequestStream写入提交时,发送到BAIDU服务器的却还是只有300多Bytes。应该是这个导致了错误的产生,因为前者在数据发送后,服务器回复的数据有1400字节左右,而后者发送后,服务器直接回复SSLAlert,只有约200字节。这两种提交方式的区别是由于IE提交SSL数据时会有一个SESSIONID,而WEBREQUEST却没有SESSIONID该如何取得呢?
解决方案:
顶一下,学习
解决方案:
参考下http://www.cnblogs.com/daohuen/archive/2008/09/28/1301468.html
解决方案:
引用17楼lovefootball的回复:

参考下http://www.cnblogs.com/daohuen/archive/2008/09/28/1301468.html

Thankyou.ButIhavetriedthisbeforeIaskedthisquestion.
解决方案:
引用17楼lovefootball的回复:

参考下http://www.cnblogs.com/daohuen/archive/2008/09/28/1301468.html

Thankyou.ButIhavetriedthisbeforeIaskedthisquestion.

时间: 2024-09-06 18:13:05

HTTPS与WEBREQUEST的问题的相关文章

SSL原理及应用(3).NET开发中处理HTTPS

在ASP.NET.SQL Server.WCF等通信领域,微软都提供了基于SSL的安全保护机制.遗憾的是,.NET并没有对SSL协议本身提供像TCP.UDP这样的基础网络协议的编程性支持.如果想从协议的角度处理SSL通信或者想构建完整的SSL框架,那么.NET帮不上你,但是还有选择,许多第三方安全通信的项目提供了支持,比如OpenSSL.这不意味着我们在此领域将无所作为,第6章介绍了.NET中操作数字证书的两个类: q  System.Security.Cryptography.X509Cert

ASP.NET1.1和2.0下进行https请求的不同实现

asp.net|请求 今天做项目中进行https请求时遇到这样的调试错误,内部错误:未能为 SSL/TLS 安全通道建立信任关系.错误页面:根据验证过程,远程证书无效.经过分析,在浏览器中打开要进行一个安全确认.就是这个对话框引起的问题.在网上搜了一下一般的解决办法,但是搜的内容比较少,现在在这里总结一下. using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Sec

zt:Consuming Webservices over HTTPS (SSL)

services|web When Webservices are used, a common concern is security: SOAP messages are transferred in plain text over the network, so anyone with a sniffer could intercept the SOAP message and read it. In my opinion this could happen also to binary

.net-请求https接口的时候提示基础连接已经关闭:连接被意外关闭

问题描述 请求https接口的时候提示基础连接已经关闭:连接被意外关闭 我把做好的.net项目部署到IIS上,项目中有POST请求别人的https接口,然后就提示: 基础连接已经关闭:连接被意外关闭,搞了一天了,都不知道怎么解决,望大神来拯救我把 解决方案 将超时设置的稍微大一些试试看 解决方案二: private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain cha

C# webrequest 抓取数据时,多个域Cookie的问题

最近研究了下如何抓取为知笔记的内容,在抓取笔记里的图片内容时,老是提示403错误,用Chorme的开发者工具看了下: 这里的Cookie来自两个域,估计为知那边是验证了token(登录后才能获取到token) 下载图片的代码: var path = "https://note.wiz.cn/" + str.TrimStart('/'); var extension = Path.GetExtension(path); var filepath = AppPath.Combine(&qu

VB.net 通过WebRequest 发送post请求 如何获取http响应

问题描述 VB.net 通过WebRequest 发送post请求 如何获取http响应 VB.net 通过WebRequest 发送post请求 如何获取http响应 解决方案 http://blog.csdn.net/skylen/article/details/7594868https://msdn.microsoft.com/zh-cn/library/system.net.webrequest.getresponse(VS.80).aspx ' Create a new WebRequ

ASP.NET访问微信商户注册HTTPS接口时报“基础连接已经关闭: 连接被意外关闭”

问题描述 测试代码如下:publicvoidBindData(){stringUrl="https://api.mch.weixin.qq.com/secapi/mch/submchmanage?action=add";Encodingencoding=Encoding.UTF8;varxml="<?xmlversion='1.0'encoding='utf-8'?><xml><appid>wxd9c866ad31c3c6da</ap

服务器A访问服务器B没有携带https客户度证书

问题描述 服务器A访问服务器B没有携带https客户度证书 我有个wcf程序部署在在iis,它会请求另外的服务器B,并携带一个客户端证书(证书是安装在电脑上面的), 我部署在自己的电脑上面win10,能正常访问另外的服务器B, 我部署在服务器winservice08 ,就不能正常发起另外的服务器B, 我通过抓包工具发现,他是没有携带 https 的客户端证书,所以服务器B断开连接了. 解决方案 那你的程序是如何提交证书来发送请求的 解决方案二: request = (HttpWebRequest

使用httprequest自动登录https网站,始终返回的是登录页面,有高手能看下么

问题描述 stringhtml="";HttpWebResponseresponse=null;this.RequestUri=newUri(url);HttpWebRequestrequest=WebRequest.Create(this.RequestUri)asHttpWebRequest;try{if(url.StartsWith("https",StringComparison.OrdinalIgnoreCase)){ServicePointManager