Coffeehouse Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

WebRequests for AnswerBag

Back to Forum: Coffeehouse
  • User profile image
    Steve411

    Hey guys,

    I have a pretty good understanding of WebRequests and WebResponse. However, I'm really having a hard time with creating a web request for the AnswerBag service.

    I'm trying to create a web request that will send a form on their login page. The page is : http://www.answerbag.com/login?

    I would like to pass the username (email in this case) and password, then get an http response.

    I already some code down but it seems to returns successful regardless if the information is valid or not.

    Anyone?

  • User profile image
    Minh

    What's your definition of successful?

    You should get a HTTP response back, even if it's HTML saying your got a bad login.

    Most likely, these these things will return a cookie collection as part of a successful login. You'll have to grab that out of the response object, and attach it back to the request object for future requests.


  • User profile image
    Cannot​Resolve​Symbol

    Minh said:
    What's your definition of successful?

    You should get a HTTP response back, even if it's HTML saying your got a bad login.

    Most likely, these these things will return a cookie collection as part of a successful login. You'll have to grab that out of the response object, and attach it back to the request object for future requests.


    Beware, using an automated service not provided by Answerbag to get data from the site (including a scraper, which is what it looks like you're doing) is explicitly against their terms of use (as it is with most sites).

  • User profile image
    Steve411

    Minh said:
    What's your definition of successful?

    You should get a HTTP response back, even if it's HTML saying your got a bad login.

    Most likely, these these things will return a cookie collection as part of a successful login. You'll have to grab that out of the response object, and attach it back to the request object for future requests.


    Succesful is when the user is succesfuly logged in a cookie collection is returned. The thing is, im using fault credentials on purpose just to test it and it seems as though it still "authenticates" it even though the site its self is not. Perhaps I am sending the wrong post data? Probably not formatted right.

    Here's the result it returns with a valid php session id:

    ---------------------------
    Return data
    ---------------------------
    Pragma: no-cache
    Vary: Accept-Encoding
    Connection: close
    Content-Language: en-us
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Content-Type: text/html; charset=utf-8
    Date: Fri, 18 Jul 2008 06:19:33 GMT
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Set-Cookie: PHPSESSID=e802967cb304c07d54129c707eadaca2; path=/
    Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.8d PHP/5.2.5
    X-Powered-By: PHP/5.2.5
    ---------------------------
    OK  
    ---------------------------


    ---------------------------
    Status page
    ---------------------------
    http://www.answerbag.com/404.php
    ---------------------------
    OK  
    ---------------------------

    And this is our execution code:

    // this is what we are sending
    string post_data = string.Format("email={0}&password={1}", account.Login, account.Password);
    // this is where we will send it
    string uri = http://www.answerbag.com/login;
    // create a request
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri + post_data);
    request.KeepAlive = false;
    request.ProtocolVersion = HttpVersion.Version10;
    request.Method = "POST";
    // turn our request string into a byte stream
    byte[] postBytes = Encoding.ASCII.GetBytes(uri+post_data);
    // this is important -
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = postBytes.Length;
    Stream requestStream = request.GetRequestStream();
    // now send it
    requestStream.Write(postBytes, 0, postBytes.Length);
    requestStream.Close();


     

  • User profile image
    Steve411

    Anyone with suggestions?

  • User profile image
    Minh

    Steve411 said:
    Anyone with suggestions?
    What's the HTML for a failed login in look like in comparison to a successful login?

  • User profile image
    Steve411

    Minh said:
    Steve411 said:
    *snip*
    What's the HTML for a failed login in look like in comparison to a successful login?
    Are you saying I should compare the two?

  • User profile image
    Minh

    Steve411 said:
    Minh said:
    *snip*
    Are you saying I should compare the two?
    Yes. If what you're seeing in a cookie always coming back, then your only alternative is to compare the returning HTML.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.