使用C#创建SSL WebRequest [英] Create a SSL WebRequest with C#
问题描述
我正在创建一个读取页面并以编程方式下载内容的代码,但它与浏览器的工作方式不同。
请注意,我也使用cookies字符串。
I'm making a code that reads the a page and downloads it contents programmatically, but it does not work same way as a browser. Note that I'm also using cookies string.
我的代码是:
string strUrl = "http:" + "//mgac.webex." + "com";
string cookies_str = "vSeg=post_attendee; s_nr=1321305381566-New; s_lv=1321305381566; s_vnum=1322686800567%26vn%3D1; galaxyb_wl=R2355168776; JSESSIONID=Qlq1TR7Hf09KTsGHr4vv2GnTFF0NGRlLmGyYmMvzY5M29pbZ8yNp!31020270; DetectionBrowserStatus=3|1|32|1|4|2; CK_LanguageID_503319=1; CK_TimeZone_503319=4; CK_RegionID_503319=2; vSeg=post_attendee; s_nr=1321305381566-New; s_lv=1321305381566; s_vnum=1322686800567%26vn%3D1; galaxyb_wl=R2355168776; JSESSIONID=Qlq1TR7Hf09KTsGHr4vv2GnTFF0NGRlLmGyYmMvzY5M29pbZ8yNp!31020270;";
string other_saved_cookies = "screenWidth=1280; CK_CDNHostStatus=akamaicdn.webex.com|1322367753273|1";
string s;
using (WebClient client = new WebClient())
{
client.UseDefaultCredentials = true;
client.Headers.Add(HttpRequestHeader.Cookie, cookies_str);
s = client.DownloadString(strUrl);
}
我得到这个答案:
无法找到页面。 ..
I get this answer: "The Page Cannot be found..."
当我用Fiddler扫描请求时,我的浏览器收到相同的答案,之后他向同一主机发出了使用SSL的新请求。
when I scan the Request with Fiddler, my browser recieves the same answer, after that he makes a new request to using SSL to same host.
我如何能够完全接受与浏览器等内容相同的请求
How can I make exactly same request to receive content like a browser
信息在哪里告诉客户:需要SSL连接?
推荐答案
这看起来像你之后的
如何使用C#中使用SSL的HTTP GET请求? (协议违规)
但将http更改为https可能是一个很好的起点!
b
然后,显然,设置一个ServicePointManager.ServerCertificateValidationCallback,如上面帖子中的2个回复所示。
But changing "http" to "https" might be a good starting point!
Then, apparently, setting a ServicePointManager.ServerCertificateValidationCallback as shown in 2 of the replies to the above post.
编辑
添加
string ua = "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0";
然后
client.Headers.Add(HttpRequestHeader.UserAgent, ua);
然后解析重定向结果的Location标头。
Then parse the Location header of the redirected result.
这篇关于使用C#创建SSL WebRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!