Aaron Gibson
Aaron Gibson

Reputation: 1378

How to Save A Captcha Image without it changing

I'm looking to login to several of my accounts for various services automatically to check data and email it to myself. Problem is the captchas. I have tried before to get around them but failed.

Can anyone confirm this one step for me that I can find seemingly no ref to anywhere. If I use c# to make a web reqeust - I can read the URL of the captcha etc but on saving it, it appears to change the value of the image as its dynamic. I can send an image to Deathbycapture etc but I cannot physically save an image from a web request without it regenerating - even if the request is not loaded into a browser - one call to the url and It seemingly makes a new image.

Any ideas.

Upvotes: 1

Views: 1990

Answers (1)

Aaron Gibson
Aaron Gibson

Reputation: 1378

Found the answer.

The issue was - When I called the URL in c# - it generated a very simple captcha - quite different to what the site showed in the browser. That was because all my calls to the captcha url didnt unclude the cookies etc that I have been using normally with the site - seems to make a big diff:

public Image GetImage(string url)
    {
        HttpWebRequest request = GetWebRequest(url);
        var responseData = "";

        if (request == null)
            return null;

        request.Method = "GET";
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.ContentType = "application/x-www-form-urlencoded";
        request.CookieContainer = cookieContainer;
        request.UserAgent = RefreshUserAgent();
        request.KeepAlive = true;
        request.AllowAutoRedirect = _allowAutoRedirect;
        request.Referer = _referer;
        request.Timeout = TimeoutInterval;

        //Decode Response
        request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

        try
        {
            var response = (HttpWebResponse)request.GetResponse();
            response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
            return Image.FromStream(response.GetResponseStream());

        }
        catch(Exception ex)
        {

            Console.WriteLine(ex.Message);
        }


        return null;
    }

Now updated my image pulling code to generate the same way as my Get/Post requests

Upvotes: 1

Related Questions