English 中文(简体)
HttpWebRequest redirect with cookies
原标题:HttpWebRequest redirect with cookies

我知道有人就HttpWebRequest提出了许多问题。 然而,我无法找到解决Im的问题的任何答案。

我需要弄清浏览器向URLs的方向。 我的法典对《欧洲刑法》做了细微的工作,但对于《欧洲刑法》则没有:

我的法典:

sURL = "http://ad2.adfarm1.adition.com/redi*lid=689397953768/sid=404178/kid=253598/bid=847344/c=33349/keyword=/sr=0/clickurl=&ClickTarget=_blank&";
CookieContainer oCookies = new CookieContainer();
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(sURL);
myHttpWebRequest.CookieContainer = oCookies;
myHttpWebRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";    
myHttpWebRequest.Accept = "text/html, application/xhtml+xml, */*";
myHttpWebRequest.Headers["Accept-Language"] = "en-GB";
myHttpWebRequest.Headers["Accept-Encoding"] = "gzip, deflate";

HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
sNewURL = myHttpWebResponse.GetResponseHeader("Location");

Fiddler by IE, Request:

GET http://ad2.adfarm1.adition.com/redi*lid=689397953768/sid=404178/kid=253598/bid=847344/c=33349/keyword=/sr=0/clickurl=&ClickTarget=_blank& HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-GB
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: ad2.adfarm1.adition.com
Cookie: fc3=101c3; co=1; UserID1=19177152736; lv_248940=w=470167|t=1321974830; lv_249431=w=125082|t=1321974853; lc_253598=w=404178|t=1321977996

Fiddler by code, Request:

GET http://ad2.adfarm1.adition.com/redi*lid=689397953768/sid=404178/kid=253598/bid=847344/c=33349/keyword=/sr=0/clickurl=&ClickTarget=_blank& HTTP/1.1
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept: text/html, application/xhtml+xml, */*
Accept-Language: en-GB
Accept-Encoding: gzip, deflate
Host: ad2.adfarm1.adition.com
Connection: Keep-Alive

Fiddler by IE, Response:

HTTP/1.1 302 Found
Server: ADITIONSERVER v1.0
Date: Tue, 22 Nov 2011 17:37:39 +0100
Connection: close
Content-Type: text/plain
Location: &ClickTarget=_blank&
P3P: policyref="http://imagesrv.adition.com/w3c/p3p.xml",CP="NOI DSP COR NID ADMo OUR NOR COM"
Set-Cookie: co=1; expires=Wed, 01-Jan-2025 00:00:00 GMT; path=/; domain=.adfarm1.adition.com
Set-Cookie: UserID1=19177152736; expires=Sun, 20-May-2012 18:37:39 GMT; path=/; domain=.adfarm1.adition.com
Set-Cookie: lc_253598=w=404178|t=1321979859; expires=Tue, 22-Nov-2011 18:07:39 GMT; path=/; domain=.adfarm1.adition.com

Fiddler by code, Response:

HTTP/1.1 302 Found
Server: ADITIONSERVER v1.0
Date: Tue, 22 Nov 2011 18:07:39 +0100
Connection: close
Content-Type: text/plain
Location: http://ad2.adfarm1.adition.com:80/redi?co=1&bid=847344&c=33349&keyword=&kid=253598&lid=689397953768&sid=404178&sr=0&clickurl=%26ClickTarget%3D%5Fblank%26
P3P: policyref="http://imagesrv.adition.com/w3c/p3p.xml",CP="NOI DSP COR NID ADMo OUR NOR COM"
Set-Cookie: co=1; expires=Wed, 01-Jan-2025 00:00:00 GMT; path=/; domain=.adfarm1.adition.com

如你所知,我从法典中得出的地点价值不同于国际独立实体。 我从菲德勒那里看到的唯一区别是,这些厨师并不是根据要求派出的。 然而,这些厨师来自哪里,我如何确定这些ok?

非常感谢

最佳回答

在您的会议期间,或者在先前与“一套电线”头对座各位的答复中,在您的座椅上,必须节省下来。

如果你想用人工 set来寄送你最初的请求,你会这样做。

CookieContainer oCookies = new CookieContainer();
            CookieCollection cookieGroup = new CookieCollection();
            Cookie userId = new Cookie("UserID1","19177152736", "/", ".adfarm1.adition.com");
            cookieGroup.Add(userId);
            oCookies.Add(cookieGroup);

之后添加到您的“吉卜赛人”网站。

myHttpWebRequest.CookieContainer = oCookies;

如果你想在随后的任何请求中加入这些 co,那么就能够确定http://WebRequests CookieContainer to oCookies。

问题回答

我认为,你不需要从你最初的请求中设立或派出任何厨师。

如果你从来不去那儿,你就应该从那里获得任何 co。

我已经通过HttpRequestObject和我永远不需要做任何 co子的记忆,做了一个网点的拆解。

Your CookieContainer object would be populated from the 1st response and you would use that on future requests to maintain state.

I would clear your cache and modify your request until it matches exactly in fiddler.

此外,从我可以记住的后方向来看,在答复中得到了注意和反映。

I ll look through some code when I get home and post any additional help if I can.

  • Jon




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签