C# Web Response - No Cookies Returned

ilPatrino

Junior Member
Joined
Sep 6, 2011
Messages
133
Reaction score
15
Ok so I have this bot for creating accounts & it was fine up until yesterday. Now when I try to Post to the web server I get a 422 unkown error response. So I check the GET request to the page before the post & apparently the response is not returning cookies.

When comparing the same thing using Chrome I'm sure that the headers are the same but the response on Chrome is returning the cookies.

Also I tried a GET request on another server using the bot & the response contained the cookies.

Anyone encounter this problem before?
 
Can we see some code? Have you compared your requests to a fiddler trace of the page you're trying to download?
 
Yeah I used HttpWebAnalyzer which does the same thing practically. What code would help?
 
After some more testing I noticed that only 1 cookie is getting stored in the cookie container(session ID) whereas on the browser there are other cookies(persistent).
 
there are several problems with cookiescontainer
, try to use CookieCollection instead and add response cookies manually to it
 
Post some code of where you are Using Cookicontainer for cookies may be you are not able to add Cookies which are returning from Response so Post Code
 
add cookies manually from response its not hard never trust cookie-container alone always best to add it manually
 
Never mind guys I solved it.
 
What was the issue? I know cookiecontainer does not set cookies when they are sent after a 302 response to a post request. Also cookies can fail if the string includes a , in the date, so on these instances best to parse manually, although I disagree with the above who said it is easy. Isn't difficult per se, just can be a bit fiddly parsing correctly all elements all the time
 
What was the issue? I know cookiecontainer does not set cookies when they are sent after a 302 response to a post request. Also cookies can fail if the string includes a , in the date, so on these instances best to parse manually, although I disagree with the above who said it is easy. Isn't difficult per se, just can be a bit fiddly parsing correctly all elements all the time

Perhaps just a dumb coding error and is embarrassed to share :)

OP don't worry, we have all been there ;)
 
For others having the problem in future save yourself some headaches and download Wireshark (Google it) so you can look at your network traffic from your software and compare to network traffic from any other legitimate application/browser.

I personally don't like using .NET native HTTP(S) support and handle it all myself using an awesome library I wrote, that way it behaves much more like whatever browser I am imitating and implements all the features I need. I've had trouble with sites using not quite 100% compliant cookies and .NET's implementation failing.
 
Back
Top