Cookie不在HttpWebRequest中发送 [英] Cookies not sending in HttpWebRequest

查看:87
本文介绍了Cookie不在HttpWebRequest中发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,因为我想使用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真的;

}

}

}

}

解决方案

首先,我联系AOL并确保您可以这样做。我b / b
会讨厌你明天在你家门口派一队警察

早上。

其次,你使用的是2.0 Framework吗?


-

info @ donotspam dowhileloop.com
http://www.dowhileloop.com 网站开发
http://publicjoe.dowhileloop.com - C#教程


" Michael Evanchik" <弥************* @ discussions.microsoft.com>写在

消息新闻:5F ********************************** @ microsof t.com ...

大家好,因为我想使用ssl,使用这个
对象似乎很容易。我试图登录到这个例子的网络服务器(aol)。但由于某种原因,
,使用ethreal和cookies嗅探我的数据包并不是随着标题和发布数据一起发送的
。这是我正在使用的代码。可以
任何人请告诉我为什么会这样?我不想回到使用
VB6和inet控件!!!

如果您在下面的课程中注意到,我正在评论
i正在尝试的不同代码。我从谷歌获得了一些提示,因为我访问了一个不同的域名,cookie不能正常工作(即使i
加载它们?)无论哪种方式,下面域中唯一的区别是一个是
https,另一个是http。我甚至使用了一个例子,其中域名
完全相同,并且仍然是数据包嗅探,我会看到没有使用此对象发送的cookie。谁能帮忙。提前谢谢!

我的命令按钮
---------------------------

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 <​​br />
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","","");

我的班级
- -------- <无线电通信使用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,字符串代理)
{
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 =" ;申请ication / 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();
}
else
{
HttpWRequest.Method =" GET";
}

HttpWResponse =(HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse。 Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
// CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
编码。 ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn +" \ n\\\
" + s;
返回;
}

类CertPolicy:ICertificatePolicy
公共布尔CheckValidationResult(ServicePoint srvPoint,X509Certificate
certifi cate,
WebRequest请求,int certificateProblem)
{
返回true;
}
}
}
}



Landi,你在谈论世界的什么。我在alerts.aol.com登录

自动为我自己发出警报。我不需要他们的许可来做我可以使用常规互联网浏览器的b $ b。您不需要像在

示例中那样使用AOL。使用cookies去任何网站都行不通。


感谢您的帮助


Mike


Landi写道:

首先,我联系AOL并确保你可以这样做。我很讨厌你明天在你家门口派一队警察。
第二,你使用的是2.0 Framework吗?

-
info @ donotspam dowhileloop.com
http://www.dowhileloop.com 网站开发
http://publicjoe.dowhileloop.com - C#教程

Michael Evanchik <弥************* @ discussions.microsoft.com>在消息新闻中写道:5F ********************************** @ microsof t.com。 ..

大家好,因为我想使用ssl,使用这个
对象似乎很容易。我试图登录到这个例子的网络服务器(aol)。但


对于

某些原因,我正在使用ethreal和cookies嗅探包


发送

以及标题和发布数据。这是我正在使用的代码。可以


任何人

请告诉我为什么会这样?我不想回到使用


VB6

和inet控制!!!

如果你在我的课程中注意到,我正在评论


正在尝试的不同代码。我从谷歌获得了一些提示,因为即使我访问了一个不同的域名,cookie也无法正常工作(即使我


加载

他们?)无论哪种方式,下面域中唯一的区别是一个是


https

,另一个是http。我甚至使用了一个示例,其中域


其中

完全相同,仍然数据包嗅探我将看不到使用此对象发送的cookie。谁能帮忙。提前谢谢!

我的命令按钮
---------------------------

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 <​​br /> 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,"","");



我的班级
----------
使用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:在这里添加构造函数逻辑
//
}

公共字符串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。添加(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 =" ;申请ication / 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();
}
else
{
HttpWRequest.Method =" GET";
}

HttpWResponse =(HttpWebResponse)HttpWRequest.GetResponse();
retrn = HttpWResponse。 Headers.ToString();
CookieJar = HttpWRequest.CookieContainer;
// CookieCol = HttpWResponse.Cookies;
StreamReader sr = new StreamReader(HttpWResponse.GetResponseStream(),
编码。 ASCII);
string s = sr.ReadToEnd();
sr.Close();
retrn = retrn +" \ n\\\
" + s;
返回;
}

类CertPolicy:ICertificatePolicy
公共布尔CheckValidationResult(ServicePoint srvPoint,X509Certificate
certifi cate,
WebRequest请求,int certificateProblem)
{
返回true;
}
}
}
}




所有我想说的是在你这样做之前请你检查AOL。

对不起给予你抬起头来。而且,最重要的是,很抱歉试图帮助你支付



顺便问一下,你知道你刚刚提供了你的用户名和密码吗?

世界?


-

info @ donotspam dowhileloop.com
http://www.dowhileloop.com 网站开发
http://publicjoe.dowhileloop.com - C#Tutorials


" Michael Evanchik" <弥************* @ discussions.microsoft.com>写在

消息新闻:1B ********************************** @ microsof t.com ...

兰迪,你在谈论世界上的什么。我登录
alerts.aol.com自动为我自己发出警报。我不需要他们的许可来做我可以使用常规互联网浏览器的
。您不需要像
示例中那样使用AOL。使用cookies去任何网站都行不通。

感谢您的帮助。

Mike

Landi写道:

首先,我联系AOL并确保你可以做这个
。我很讨厌你明天在你家门口有一支警察队伍。
第二,你使用2.0框架吗?

-
info @ donotspam dowhileloop.com
http://www.dowhileloop.com 网站开发
http://publicjoe.dowhileloop.com - C#教程

Michael Evanchik <弥************* @ discussions.microsoft.com>在消息新闻中写道:5F ********************************** @ microsof t.com。 ..

大家好,因为我想使用ssl,并且使用
这个对象似乎很容易。我试图登录到这个例子的网络服务器(aol)。

for

某些原因,我正在使用ethreal和cookies嗅探数据包


发送

以及标题和发布数据。这是我正在使用的代码。可以


任何人

请告诉我为什么会这样?我不想回到


使用VB6

和inet控件!!!

如果你在我的课程中注意到下面,我正在评论不同的代码


我正在尝试

。我从谷歌获得了一些提示,因为即使我访问了一个不同的域名,cookie也无法正常工作(即使我


加载

他们?)无论哪种方式,下面域中唯一的区别是一个是


https

,另一个是http。我甚至使用了一个例子,其中


域名

完全相同,但仍然是数据包嗅探我会看到没有cookie


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
{< br => 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 this
object. Im trying to login to a webserver (aol) for this example. But for
some reason, im packet sniffing with ethreal and cookies are not being sent
along with the header and post data. here is the code im using. Can anyone
please tell me why this is happening? I do not want to go back to using VB6
and the inet control!!!

If you notice in my class below, i was commenting out different codes that i
was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded
them?) Either way, the only difference in the domain below is one is a https
and the other is a http. I have even used an example where the domains where
exactly the same, and still packet sniffing i would see no cookies beeing
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=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, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}

解决方案

First of all I contact AOL and make sure it''s ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"Michael Evanchik" <Mi*************@discussions.microsoft.com> wrote in
message news:5F**********************************@microsof t.com...

Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal and cookies are not being sent along with the header and post data. here is the code im using. Can anyone please tell me why this is happening? I do not want to go back to using VB6 and the inet control!!!

If you notice in my class below, i was commenting out different codes that i was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i loaded them?) Either way, the only difference in the domain below is one is a https and the other is a http. I have even used an example where the domains where exactly the same, and still packet sniffing i would see no cookies beeing
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","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","","");

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, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}



Landi, what in the world are you talking about. Im loggin in alerts.aol.com
to automate alerts for myself. I do not need their permission to do what i
can using a regular internet browswer. You do not need to use AOL as in
example. Going to any website using cookies it would not work.

Thank for no help

Mike

"Landi" wrote:

First of all I contact AOL and make sure it''s ok for you to be doing this. I
would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"Michael Evanchik" <Mi*************@discussions.microsoft.com> wrote in
message news:5F**********************************@microsof t.com...

Hello all, since i wanted to use ssl and its seems easy to do so with this
object. Im trying to login to a webserver (aol) for this example. But


for

some reason, im packet sniffing with ethreal and cookies are not being


sent

along with the header and post data. here is the code im using. Can


anyone

please tell me why this is happening? I do not want to go back to using


VB6

and the inet control!!!

If you notice in my class below, i was commenting out different codes that


i

was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i


loaded

them?) Either way, the only difference in the domain below is one is a


https

and the other is a http. I have even used an example where the domains


where

exactly the same, and still packet sniffing i would see no cookies beeing
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","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","","");



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, X509Certificate
certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}




All I meant to say was for you to check up with AOL before you do that.
Sorry for giving you the heads up. And, above all, sorry for trying to help
you out.

By the way, do you know that you just gave out your username and password to
the world?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"Michael Evanchik" <Mi*************@discussions.microsoft.com> wrote in
message news:1B**********************************@microsof t.com...

Landi, what in the world are you talking about. Im loggin in alerts.aol.com to automate alerts for myself. I do not need their permission to do what i can using a regular internet browswer. You do not need to use AOL as in
example. Going to any website using cookies it would not work.

Thank for no help

Mike

"Landi" wrote:

First of all I contact AOL and make sure it''s ok for you to be doing this. I would hate it for you to have an army of police at your door tomorrow
morning.
Second, are you using 2.0 Framework?

--
info@donotspam dowhileloop.com
http://www.dowhileloop.com web development
http://publicjoe.dowhileloop.com -- C# Tutorials

"Michael Evanchik" <Mi*************@discussions.microsoft.com> wrote in
message news:5F**********************************@microsof t.com...

Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But

for

some reason, im packet sniffing with ethreal and cookies are not being


sent

along with the header and post data. here is the code im using. Can


anyone

please tell me why this is happening? I do not want to go back to

using VB6

and the inet control!!!

If you notice in my class below, i was commenting out different codes

that i

was trying. I was getting some hint from google since im accessing a
different domain name that the cookies would not work (even though i


loaded

them?) Either way, the only difference in the domain below is one is a


https

and the other is a http. I have even used an example where the

domains where

exactly the same, and still packet sniffing i would see no cookies

beeing 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","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","","");



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, X509Certificate certificate,
WebRequest request, int certificateProblem)
{
return true;
}
}
}
}




这篇关于Cookie不在HttpWebRequest中发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆