本文介绍了Cookie不在HttpWebRequest中发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好,因为我想使用ssl,使用这个 对象似乎很容易。我试图登录到这个例子的网络服务器(aol)。但是对于 某些原因,使用ethreal和cookies进行的数据包嗅探并没有发送 以及标题和发布数据。这是我正在使用的代码。谁能 请告诉我为什么会这样?我不想回到使用VB6 和inet控制!!! 如果你在我的课程中注意到,我正在评论不同我正在尝试的代码是b $ b。我从谷歌那里获得了一些提示,因为即使我访问了一个 不同的域名,这个cookie也行不通(即使我加载了 吗?)无论哪种方式,唯一的区别在下面的域中,一个是https ,另一个是http。我甚至使用了一个例子,其中 的域名完全相同,但仍然会发现数据包嗅探我看不到使用此对象发送的cookie 。谁能帮忙。提前谢谢! 我的命令按钮 ---------------------- ----- ret = htp.httpit(" https://my.screenname.aol.com/_cqr/login/login.psp" ;,,sitedomain = alertsFEmain& siteId = alertsF Emain& lang = en& locale = us& authLev = 1& siteState = OrigUr l%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fs hared%252Fnoauth.ev%253Ff%253D1%2526& isSiteStateEn coded = true& mcState = initialized& usrd = 1870944& loginI d = apientry& password = highview& rememberMe = off",""); ret = htp.httpit(" http://my.screenname.aol.com/_cqr/login/login.psp?mcState=copyCookies&siteId=alertsFEmain& authLev = 1& siteState = OrigUrl%3Dhttp%253A%252F%252Fa lerts.aol.com%252Far %252Fshared%252Fnoauth.ev%253F f%253D1%2526& isSiteStateEncoded = true& lang = en& local e = us","",""); my class ---------- 使用System; 使用System.Net; 使用System.Security.Cryptography.X509Certificates; 使用System.Threading; 使用System.IO; 使用System。文字; 命名空间backupbatch { ///< summary> // / http摘要说明 ///< / summary> 公共类http { ManualResetEvent wait = new ManualResetEvent(false); CookieContainer CookieJar = new CookieContainer(); CookieCollection CookieCol = new CookieCollection(); HttpWebResponse HttpWResponse; Uri lasturl; string retrn ="" ;; int ret; public http() { // // TODO:在这里添加构造函数逻辑 / / } 公共字符串httpit(字符串url,字符串poststr,字符串代理) { if( url.IndexOf(" https")> 1) { ServicePointManager.CertificatePolicy = new CertPolicy(); } if (proxy.Length> 0) { WebProxy proxyObject = new WebProxy(proxy.ToString()+":80",true); GlobalProxySelection.Select = proxyObject; } HttpWebRequest HttpWRequest =(HttpWebRequest)WebRequest.Create(url); HttpWRequest.CookieContainer = CookieJar; // if(retrn.Length> 0) // { // HttpWRequest。 CookieContainer.Add(lasturl,CookieCol); //} // lasturl = new Uri(" https://my.screenname.aol.com") ; HttpWRequest.Credentials = CredentialCache.DefaultCredentials; HttpWRequest.UserAgent =" your mother"; HttpWRequest.KeepAlive = false; HttpWRequest.Headers.Set(" Pragma"," no-cache"); HttpWRequest.Timeout = 300000; if(b) poststr.Length> 0) { HttpWRequest.Method =" POST"; HttpWRequest.ContentType =" application / x-www-form-urlencoded"; byte [] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToStri ng()); HttpWRequest.ContentLength = PostData.Length; 流tempStream = HttpWRequest.GetRequestStream(); tempStream.Write(PostData,0,PostData.Length); tempStream.Close(); } 其他 { HttpWRequest.Method =" GET"; } HttpWResponse =(HttpWebResponse)HttpWRequest.GetResponse(); retrn = HttpWResponse.Headers.ToString(); CookieJar = HttpWRequest。 CookieContainer; // CookieCol = HttpWResponse.Cookies; StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(), Encoding.ASCII) ; string s = sr.ReadToEnd(); sr.Close(); retrn = retrn +" \ nn \" + S ; 返回后退; } 类CertPolicy:ICertificatePolicy { public bool CheckValidationResult(ServicePoint srvPoint,X509Certificate 证书, WebRequest请求,int certificateProblem) { return真的; } } } } 解决方案 对于 发送 任何人 VB6 加载 https 其中 发送 任何人 使用VB6 我正在尝试 加载 https 域名 beeing与这个对象。谁能帮忙。提前谢谢! 我的命令按钮 --------------------------- ret = htp.httpit(" https://my.screenname.aol.com/_cqr/login/login.psp"," sitedom ain = alertsFEmain& siteId = alertsFEmain& lang = en& local e = us& authLev = 1& siteState = O rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth .ev%2 53Ff%253D1%2526& isSiteStateEncoded = true& mcState = in itialized& usrd = 1870944& log inId = apientry& password = highview& rememberMe = off",""); ret = htp.httpit(" http://my.screenname.aol.com/_cqr/login/login.psp?mcState = co pyCookies& siteId = alertsFEmain& authLev = 1& siteState = OrigUrl%3Dhttp%253A%252F%2 52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253Ff%253D1%2526& isSiteSta teEncoded =真安培;朗= EN&安培;语言环境= US","",""); 我的班级 ---------- 使用System; 使用System.Net; 使用System.Security.Cryptography.X509Certificates; 使用System.Threading; 使用System.IO; 使用System.Text; 命名空间backupbatch { ///< summary> /// http的概要说明 ///< / summary> 公共类http { ManualResetEvent wait = new ManualResetEvent(false); CookieContainer CookieJar = new CookieContainer(); CookieCollection CookieCol = new CookieCollection(); HttpWebResponse HttpWResponse; Uri lasturl; string retrn ="" ;; int ret; public http() { // // TODO:在这里添加构造函数逻辑 // } public string httpit(string url,string poststr,string proxy) { if(url.IndexOf (" https")> 1) {ServicePointManager.CertificatePolicy = new CertPolicy(); } if(proxy.Length> 0) { WebProxy proxyObject = new WebProxy(proxy.ToString()+":80",true); GlobalProxySelection.Select = proxyObject; } HttpWebRequest HttpWRequest =(HttpWebRequest )WebRequest.Create(url); HttpWRequest.CookieContainer = CookieJar; // if(retrn.Length> 0) // { // HttpWRequest.CookieContainer。添加(lasturl,CookieCol); //} // lasturl = new Uri(" https://my.screenname.aol.com"); HttpWRequest.Credentials = CredentialCache.DefaultCredentials; HttpWRequest.UserAgent =" your mother"; HttpWRequest.KeepAlive = false; HttpWRequest.Headers.Set(" Pragma"," no-cache"); HttpWRequest.Timeout = 300000; if(poststr.Length> 0) { HttpWRequest.Method =" POST"; HttpWRequest.ContentType =" application / x-www- form-urlencoded" ;; byte [] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToStri ng()); HttpWRequest.ContentLength = PostData.Length; 流tempStream = HttpWRequest.GetRequestStream(); tempStream.Write(PostData,0,PostData.Length); tempStream.Close(); } 其他 { HttpWRequest.Method =" GET" ;; } HttpWResponse =(HttpWebResponse)HttpWRequest.GetResponse(); retrn = HttpWResponse.Headers.ToString(); CookieJar = HttpWRequest.CookieContainer; // CookieCol = HttpWResponse.Cookies; StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream( ), Encoding.ASCII); string s = sr.ReadToEnd(); sr.Close(); retrn = retrn +" \ n\\\" ; + s; 返回后退; } 类CertPolicy:ICertificatePolicy 公共bool CheckValidationResult(ServicePoint srvPoint, X509证书证书) , WebRequest请求,int certificateProblem) {返回true; } } } } Hello all, since i wanted to use ssl and its seems easy to do so with thisobject. Im trying to login to a webserver (aol) for this example. But forsome reason, im packet sniffing with ethreal and cookies are not being sentalong with the header and post data. here is the code im using. Can anyoneplease tell me why this is happening? I do not want to go back to using VB6and the inet control!!!If you notice in my class below, i was commenting out different codes that iwas trying. I was getting some hint from google since im accessing adifferent domain name that the cookies would not work (even though i loadedthem?) Either way, the only difference in the domain below is one is a httpsand the other is a http. I have even used an example where the domains whereexactly the same, and still packet sniffing i would see no cookies beeingsent with this object. Can anyone help. Thank you in advance!my command button---------------------------ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedomain=alertsFEmain&siteId=alertsF Emain&lang=en&locale=us&authLev=1&siteState=OrigUr l%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fs hared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEn coded=true&mcState=initialized&usrd=1870944&loginI d=apientry&password=highview&rememberMe=off","");ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=copyCookies&siteId=alertsFEmain& authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Fa lerts.aol.com%252Far%252Fshared%252Fnoauth.ev%253F f%253D1%2526&isSiteStateEncoded=true&lang=en&local e=us","","");my class----------using System;using System.Net;using System.Security.Cryptography.X509Certificates;using System.Threading;using System.IO;using System.Text;namespace backupbatch{/// <summary>/// Summary description for http./// </summary>public class http{ManualResetEvent wait = new ManualResetEvent(false);CookieContainer CookieJar = new CookieContainer();CookieCollection CookieCol = new CookieCollection();HttpWebResponse HttpWResponse;Uri lasturl;string retrn = "";int ret;public http(){//// TODO: Add constructor logic here//}public string httpit(string url, string poststr, string proxy){if (url.IndexOf("https") > 1){ServicePointManager.CertificatePolicy = new CertPolicy();}if (proxy.Length > 0){WebProxy proxyObject = new WebProxy(proxy.ToString()+ ":80",true);GlobalProxySelection.Select = proxyObject;}HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);HttpWRequest.CookieContainer = CookieJar;//if (retrn.Length > 0)//{//HttpWRequest.CookieContainer.Add(lasturl, CookieCol);//}//lasturl = new Uri("https://my.screenname.aol.com");HttpWRequest.Credentials = CredentialCache.DefaultCredentials;HttpWRequest.UserAgent = "your mother";HttpWRequest.KeepAlive = false;HttpWRequest.Headers.Set("Pragma", "no-cache");HttpWRequest.Timeout = 300000;if(poststr.Length > 0 ){HttpWRequest.Method = "POST";HttpWRequest.ContentType = "application/x-www-form-urlencoded";byte[] PostData = System.Text.Encoding.ASCII.GetBytes(poststr.ToStri ng());HttpWRequest.ContentLength = PostData.Length;Stream tempStream = HttpWRequest.GetRequestStream();tempStream.Write(PostData,0,PostData.Length);tempStream.Close();}else{HttpWRequest.Method = "GET";}HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();retrn = HttpWResponse.Headers.ToString();CookieJar = HttpWRequest.CookieContainer;//CookieCol = HttpWResponse.Cookies;StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),Encoding.ASCII);string s = sr.ReadToEnd();sr.Close();retrn = retrn + "\n\n"+s;return retrn;}class CertPolicy: ICertificatePolicy{public bool CheckValidationResult(ServicePoint srvPoint, X509Certificatecertificate,WebRequest request,int certificateProblem){return true;}}}} 解决方案 for sent anyone VB6 i loaded https where ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedom ain=alertsFEmain&siteId=alertsFEmain&lang=en&local e=us&authLev=1&siteState=O rigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far% 252Fshared%252Fnoauth.ev%2 53Ff%253D1%2526&isSiteStateEncoded=true&mcState=in itialized&usrd=1870944&log inId=apientry&password=highview&rememberMe=off","" ); ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=co pyCookies&siteId=alertsFEmain&authLev=1&siteState= OrigUrl%3Dhttp%253A%252F%2 52Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev% 253Ff%253D1%2526&isSiteSta teEncoded=true&lang=en&locale=us","",""); sent anyoneusing VB6that i loaded httpsdomains wherebeeing sent with this object. Can anyone help. Thank you in advance! my command button ---------------------------ret=htp.httpit("https://my.screenname.aol.com/_cqr/login/login.psp","sitedomain=alertsFEmain&siteId=alertsFEmain&lang=en&local e=us&authLev=1&siteState=OrigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far% 252Fshared%252Fnoauth.ev%253Ff%253D1%2526&isSiteStateEncoded=true&mcState=in itialized&usrd=1870944&log inId=apientry&password=highview&rememberMe=off","" );ret=htp.httpit("http://my.screenname.aol.com/_cqr/login/login.psp?mcState=copyCookies&siteId=alertsFEmain&authLev=1&siteState= OrigUrl%3Dhttp%253A%252F%252Falerts.aol.com%252Far%252Fshared%252Fnoauth.ev% 253Ff%253D1%2526&isSiteSta teEncoded=true&lang=en&locale=us","",""); 这篇关于Cookie不在HttpWebRequest中发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-14 07:24