'Getting wrong hash in location header on Http request

I am trying to make a Bookstore application. To download any book there is a redirect link that contains the actual link with the filename to download the epub file. But when I load the first link and try to get the redirect link from the location header I get the wrong link.

Code:

String url = "https://1lib.in/dl/4649171/4e15a5";
URL url2 = new URL(url);
            HttpURLConnection httpConn = (HttpURLConnection) url2.openConnection();
            httpConn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
            httpConn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36");
            httpConn.addRequestProperty("Referer", "https://www.google.com");
            httpConn.setInstanceFollowRedirects(false);
            httpConn.setRequestMethod("GET");
            httpConn.connect();
int responseCode = httpConn.getResponseCode();
            Log.d("LocationHeader",responseCode+" <-code");
            String locate = httpConn.getHeaderField("Location");
            Log.d("LocationHeader",locate+" <-location");

This is the response that I get.

LocationHeader: 302 <-code
LocationHeader: https://1lib.in/book/4649171/371aea/?wrongHash <-location

Expected Result:

LocationHeader: https://p302.zlibcdn.com/dtoken/aaa62058cd53e7318e2f511f4d1fbd3f <-location

Also tried the request in Postman but got the same results there.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source