java - Read InputStream from file via URL query string -


is possible use java url.openstream() method read file input stream when url query string rather direct link file? e.g. code have is:

url myurl = new url("http://www.test.com/myfile.doc"); inputstream = myurl.openstream();  

this works fine direct file link. if url http://www.test.com?file=myfile.doc ? still able obtain file stream server response?

thanks!

generally yes, work.

but note url.openstream() method doesn't follow redirects , not agile specifying additional http behaviours: request type, headers, etc.

i'd recommend use apache http client instead:

final closeablehttpclient httpclient = httpclients.createdefault();          final httpget request = new httpget("http://any-url");  try (closeablehttpresponse response = httpclient.execute(request)) {     final int status = response.getstatusline().getstatuscode();      if (status == 200) {         final inputstream = response.getentity().getcontent();     } else {         throw new ioexception("got " + status + " server!");     } } {     request.reset(); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -