如何直接获取图像?

发布于 2024-10-03 22:48:18 字数 874 浏览 0 评论 0原文

以下网页包含轻度成人内容。如果您不想要,请不要点击链接。

  1. 转到:http://www.hqasians.com/tgp/bigasiantits/MaiNishida/ at.htm
  2. 你可以看到几个拇指图像。
  3. 单击其中之一。你可以看到大图。
  4. 检查当前页面网址。它将像 ~~~~~~~~~~~~~~~~/tgp/bigasiantits/MaiNishida/images/01.jpg
  5. 的最后一个 .jpg 名称来知道如何访问另一个图像
  6. 你可以通过更改整个网址更改 01.jpg 改为 02.jpg 并输入。
  7. 但是,您会遇到网站的主页而不是02.jpg。

这是阻止该站点直接访问的安全方法吗?

有没有什么解决方法可以直接获取图像?


以下是我的代码。

输入流bmis;

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

最终的可绘制图像 =

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

if(image != null)

{

activity.setContentView(imageSwitcher);    

imageSwitcher.setImageDrawable(image);

}

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);

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花心好男孩 2024-10-10 22:48:18

我只是在这里猜测,但我认为这个网站所做的是检查 HTTP 请求标头中的“Referer”字段,以检查请求是来自网站内部还是来自外部。

这不是阻止直接访问的安全方法。事实上,有一个解决方法,但我认为网站规则不允许我在这里写它,所以,你必须自己弄清楚。

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.

九厘米的零° 2024-10-10 22:48:18

这是因为推荐人。您必须通过该主页来打开图片。

抱歉,我不知道如何使用 Android,但 C# 代码应该如下所示:

   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);
        }
    }

CopyStream 方法从此处获取:如何在 C# 中将流保存到文件?

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#?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文