Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using jsoup to connect a url

the url redirects to another one by 302

I want to get the main url (second one after redirection)

Here is the code:

Connection.Response response = Jsoup
.connect(f_url[0])
.method(Connection.Method.GET)
.followRedirects(false)
.header("Accept", "image/png,image/*;q=0.8,*/*;q=0.5")
.header("Accept-Encoding", "gzip, deflate")
.header("Accept-Language", "en-US,en;q=0.5")
.header("Connection", "keep-alive")
.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0")
.timeout(globalData.WEB_TIME_OUT).execute();
String the_url = response.header("Location");

The problem : I get ioexception I'm sure the url is correct its a file for download i have tested it.it redirects to main address and the file starts to download

java.io.IOException: 400 error loading URL
share|improve this question
    
Does changing followRedirects to true change anything? –  Ken Wolf Jun 10 '13 at 12:29
    
400 means bad request... But I don't see anything wrong here :/ –  fge Jun 10 '13 at 12:31
    
Yes it raises java.net.SocketTimeoutException thats why i've set followRedirects false the URL is laserpeh.ir/milad/redirect_it/Full-Album/Hengameh/… –  mi1s0n Jun 10 '13 at 12:34
    
Are the spaces in the url the problem?If yes how can i fix it? –  mi1s0n Jun 10 '13 at 12:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.