1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Web Response - No Cookies Returned

Discussion in 'C, C++, C#' started by ilPatrino, Jul 25, 2012.

  1. ilPatrino

    ilPatrino Junior Member

    Joined:
    Sep 6, 2011
    Messages:
    130
    Likes Received:
    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?
     
  2. Chris22

    Chris22 Regular Member

    Joined:
    Sep 29, 2010
    Messages:
    400
    Likes Received:
    1,059
    Can we see some code? Have you compared your requests to a fiddler trace of the page you're trying to download?
     
  3. ilPatrino

    ilPatrino Junior Member

    Joined:
    Sep 6, 2011
    Messages:
    130
    Likes Received:
    15
    Yeah I used HttpWebAnalyzer which does the same thing practically. What code would help?
     
  4. ilPatrino

    ilPatrino Junior Member

    Joined:
    Sep 6, 2011
    Messages:
    130
    Likes Received:
    15
    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).
     
  5. haylander

    haylander Registered Member

    Joined:
    May 24, 2009
    Messages:
    54
    Likes Received:
    20
    there are several problems with cookiescontainer
    , try to use CookieCollection instead and add response cookies manually to it
     
  6. shubhamm

    shubhamm Junior Member

    Joined:
    Jan 25, 2010
    Messages:
    107
    Likes Received:
    25
    Occupation:
    Developer
    Location:
    BHW
    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
     
  7. kelvin.thechamp

    kelvin.thechamp Power Member

    Joined:
    Apr 4, 2011
    Messages:
    643
    Likes Received:
    272
    Occupation:
    Account selling , Creating Multithread Bot's
    Location:
    http://spamvilla.com
    add cookies manually from response its not hard never trust cookie-container alone always best to add it manually
     
  8. ilPatrino

    ilPatrino Junior Member

    Joined:
    Sep 6, 2011
    Messages:
    130
    Likes Received:
    15
    Never mind guys I solved it.
     
  9. rootjazz

    rootjazz Jr. VIP Jr. VIP

    Joined:
    Dec 21, 2012
    Messages:
    614
    Likes Received:
    313
    Occupation:
    Developer
    Location:
    UK
    Home Page:
    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
     
  10. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    575
    Likes Received:
    212
    The forum ettiquete is to tell how you solved it. Because it can help in the future for the other people.
     
  11. rootjazz

    rootjazz Jr. VIP Jr. VIP

    Joined:
    Dec 21, 2012
    Messages:
    614
    Likes Received:
    313
    Occupation:
    Developer
    Location:
    UK
    Home Page:
    Perhaps just a dumb coding error and is embarrassed to share :)

    OP don't worry, we have all been there ;)
     
  12. ampedsoftware

    ampedsoftware Newbie

    Joined:
    Dec 25, 2012
    Messages:
    26
    Likes Received:
    12
    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.