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.
E.g.
- Open
http://mywebsite.com
http://mywebsite.com
loads and 开发者_运维百科opens up a new tab tohttp://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.
精彩评论