Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within I/O and Streams
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
I/O and Streams
HttpClient just wont download a audio file
olze oli
Ranch Hand
Posts: 187
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi,
i have the following code:
HttpPost getStreamPost = new HttpPost("http://" + streamServer"); getStreamPost.setHeaders(httppost.getAllHeaders()); getStreamPost.setParams(httppost.getParams()); getStreamPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); StringEntity streamKeyEntity = new StringEntity("id=" + streamKey, "UTF-8"); getStreamPost.setEntity(streamKeyEntity); HttpEntity mp3Stream = execute(getStreamPost).getEntity(); if (mp3Stream != null) { FileOutputStream fos = new FileOutputStream(song.getSongName() + " - " + song.getArtist()); InputStream inputStream = mp3Stream.getContent(); byte[] buffer = new byte[1024]; while (inputStream.read(buffer) > 0) { fos.write(buffer); } fos.flush(); fos.close(); mp3Stream.consumeContent(); }
but it wont download the file.
i retrieve a 302 Found from the server, but httpclient wont follow
when i
test
another website where i'm sure that there will be no 302 then it works
can someone please help me? :/
Rob Spoor
Sheriff
Posts: 22783
131
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
302 means that there is a temporary redirect. Check out the getFollowRedirects and setFollowRedirects of HttpMethod. It should be set to true.
For your information, HttpURLConnection and probably most other classes for connecting to web servers have similar methods.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
olze oli
Ranch Hand
Posts: 187
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
its a HttpPost, looks like there's no such method
olze oli
Ranch Hand
Posts: 187
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
so as i heard its against some RFC or so... but FF, IE and so on can handle it
the overwritten code which works for me is:
HttpClient client = new HttpClient(); client.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public boolean isRedirected(HttpRequest hr, HttpResponse hr1, HttpContext hc) { if (hr1.getStatusLine().getStatusCode() == 302) { return true; } return false; } @Override public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) { HttpGet get = null; try { String newLocation = "" + response.getFirstHeader("Location"); newLocation = newLocation.substring(newLocation.indexOf("Location:")+10); get = new HttpGet(newLocation); } catch (Exception ex) { System.out.println(ex.getLocalizedMessage()); } return get; } });
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
HttpClient 4 and SOAP
upload file through applet
Sending a jason object via Post
Post an XML filt to a Web Server
Cannot download the whole text file
More...