Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

Anyone out there familiar with the old WinInet routines for httpsendrequest and httpopenrequest and such? Although it wasn't as easy to work with as HttpWebRequest, it did have features that seem to be missing in HttpWebRequest. For example, the whole cookie thing... by default the WinInet libraries would get the current cookie for the domain you were requesting the page for from IE, and put it in the headers, that way sites that a user was logged into that I was interacting with, automatically found the login information. With the HttpWebRequest, that is completely lacking... now that said, I know it is possible to add a cookie manually to the header, but they don't even give a way to look up the default cookie that the current user has for it. I am stuck using the old InternetGetCookie WinInet function to do that. Plus, since it doesn't automatically get the cookie, it doesn't automatically update the users cookie if a change is made.

 

By default, all the cookie operations were happening in WinInet so that it would get the current cookie, and change the current cookie in the browser if a change was detected. This behavior could be turned off obviously, but it was very helpful.

 

It seems to me that with HttpWebRequest, there is not even a setting for this behavior to continue. Furthermore, it doesn't offer the functions necessary to get the current cookie (must revert back to using InternetGetCookie in WinInet). Am I wrong about this? Is there some hidden setting that I am not seeing that I can change to make it do what WinInet use to do?

 

I know it sounds like I'm just complaining a lot, but one of the problems I have run into is that even when I set the cookie manually, then make a request, if the request is redirected (you can set the max number of redirects) it doesn't use the cookie I set for it to use when it is redirected, so it is like the user is not logged in again. The problem is that a lot of the pages have automatic redirects when you are submitting data to a form and such, so suddenly the response I get back doesn't even have the user logged in anymore.

 

Sorry for rambling :-P If you made it this far you deserve some milk with those cookies.

mov ax, 13h

int 10h

  • *Experts*
Posted

I'm not sure I understan what you're trying to do with all that rambling... :)

 

The HttpWebRequest has a CookieContainer property that lets

you retrieve the cookies associated with the request. The

HttpWebResponse has a Cookies collection which does the same

thing, only for the web response.

 

You could also use the request's

Headers collection and find the get-cookie one (or whatever the

response cookie header is called). To set a cookie, just send a

response in a HttpWebResponse's Headers collection, with

Set-Cookie and the cookie values.

 

Does that help?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

I know it can be done using that, but the problem is that I need to get the users existing cookie that they have in IE using the InternetGetCookie in order to add it to the HttpWebRequest.

 

Also, even if I have a cookie in the HttpWebRequest, if it is redirected by the server, the cookie doesnt get sent to the page it is redirected to.

 

Also, since I have to manually get the cookie, then add it to the CookieContainer, when I receive each response, I need to use InternetSetCookie (wininet) to set the IE cookie so it is updated in case the user wants to go to the site manually in a browser.

 

Are you familiar with working with cookies and sites that require cookie authentication using WinInet?

mov ax, 13h

int 10h

  • *Experts*
Posted

I'm afraid I don't know how to go about this, sorry. I was hoping it

was something simple that I mentioned that would help. :)

 

Maybe someone else can pick this up...

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • 2 years later...
Posted

Pain in the ***

 

I got the same problem. I'm trying to write a little web spider that would get the odds from http://www.betbase.info.

Page uses cookie to let you in, so i need to use it the same way that browsers do.

I can access first page, but when i try to go anywhere else, i get redirection exception (infinite loop).

If I find anything else about this I'll let you know

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...