简体   繁体   中英

Java - How to programmatically download an attachment from a URL which opens a new tab?

I need to download an attachment from a URL (say http://mywebsite.com ) programmatically using Java . The tricky part is that the above URL opens up a new tab/window onload from which the downloading actually starts.

Eg

  1. Open http://mywebsite.com
  2. http://mywebsite.com loads and opens up a new tab to http://mywebsite.com/attachments/someRandomFileName.pdf

*Note the file name in step 2 (above) is randomly assigned so I cannot hit http://mywebsite.com/attachments/someRandomFileName.pdf directly.

Thanks in advance!

The whole point of randomly generated URLs is to prevent people to access content directly.

They probably want users to go through their web site to access the file. There are numerous ways to check that request is coming from a real user/browser. This includes executing javascript and/or flash. Random URLs are generated on server and at some point they will be sent to browser.

So basically, to download a file, you'd have to look at what their web site is doing, what kind of requests it is making and what replies it gets from servers. Then try to reverse engineer this to get directly to random URL representing the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM