user518314
user518314

Reputation: 51

How to get image directly?

Follwing webpage includes light adult contents. Please do not click link if you don't want it.

  1. go to : http://www.hqasians.com/tgp/bigasiantits/MaiNishida/at.htm
  2. you can see several thumb images.
  3. click one of them. you can see large image.
  4. Check current page url. It will be like ~~~~~~~~~~~~~~~~/tgp/bigasiantits/MaiNishida/images/01.jpg
  5. you can know how to access another image by changing last .jpg name of whole url
  6. change 01.jpg to 02.jpg and enter.
  7. But, you will encounter website's main page not 02.jpg.

Is this security way to block direct access by that site ?

Is there any work-around way to get image directly?


Following is my codes.

InputStream bmis;

bmis = new URL(params[0]).openStream();

final Drawable image =

new BitmapDrawable(BitmapFactory.decodeStream(new FlushedInputStream(bmis)));

if(image != null)

{

activity.setContentView(imageSwitcher);    

imageSwitcher.setImageDrawable(image);

}

Upvotes: 0

Views: 210

Answers (2)

Shuo
Shuo

Reputation: 4849

It's because of the Referrer. You have to be referred by that main page to open the picture.

Sorry I'm not sure how to use Android, but C# code should look like this:

   static void Main(string[] args)
    {
        for (int i = 1; i <= 15; i++)
        {
            HttpWebRequest request = 
                WebRequest.Create(
                    string.Format("http://www.hqasians.com/tgp/bigasiantits/MaiNishida/images/{0:00}.jpg", i)
                    ) as HttpWebRequest;
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Referer = "http://www.hqasians.com/tgp/bigasiantits/MaiNishida/at.htm";
            request.Method = "POST";
            WebResponse response = request.GetResponse();
            string inputFile = string.Format("{0}.jpg", i);
            Console.WriteLine(response.ResponseUri.AbsoluteUri);
            using (Stream file = File.OpenWrite(inputFile))
            {
                CopyStream(response.GetResponseStream(), file);
            }
        }
    }

    /// <summary>
    /// Copies the contents of input to output. Doesn't close either stream.
    /// </summary>
    public static void CopyStream(Stream input, Stream output)
    {
        byte[] buffer = new byte[8 * 1024];
        int len;
        while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, len);
        }
    }

The CopyStream method is got from here: How do I save a stream to a file in C#?

Upvotes: 0

Carlos Melo
Carlos Melo

Reputation: 3152

I'm only guessing here, but I think what this site does is to check the "Referer" field from the HTTP request header to check whether the request came from within the site, or from outside.

It isn't a secure way of blocking direct access. In fact, there's an workaround, but I don't think the site rules allow me to write it here, so, you'll have to figure out yourself.

Upvotes: 1

Related Questions