In My android Application i have a list of song.User can download any of song from it. But my problem is when i download a file using http request it return content length = 0 or -1 so i can not download file. When i use same url in browser then song downloaded completely. My code to download a song file is -
URL url = new URL(mUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setConnectTimeout(TimeOut);
connection.setReadTimeout(TimeOut);
connection.connect();
int lenghtOfFile = connection.getContentLength();
and file length is either 0 or -1. What the problem in my code.
Thanks in advance.
0 comments:
Post a Comment