0

Just trying to use a files direct download link to download it but I keep getting this error around 1/3 times I run it, the other 2 times it runs properly like its supposed to. java.io.IOException: Server returned HTTP response code: 403 for URL:

This is my code

public static void copyUrlToFile(URL url, File destination) throws IOException {
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2");
        connection.connect();
        FileUtils.copyInputStreamToFile(connection.getInputStream(), destination);
    }```
  • This can only be answered by the owner of the HPPT server you're calling. Maybe they're throttling you, maybe your usage pattern is not allowed, etc. A 403 error means that you are not authorized to issue that request; but the fact that it's random-ish says something about that logic being around your calls. It could also be that one of their servers is misconfigured. In any case, only the owner/admin of that server can answer. – ernest_k Mar 20 '22 at 05:47
  • It is a google drive file with a shared direct download link. – JewishBanana Mar 20 '22 at 06:27
  • Does this answer your question? [java google drive api V3 MultiPart & Resumable Upload](https://stackoverflow.com/questions/62102721/java-google-drive-api-v3-multipart-resumable-upload) – Sync it Mar 20 '22 at 08:02
  • No, that is for uploading but I am downloading. I don't believe it has my solution in it. I am downloading from a public direct link so I don't need credentials, using what I have it downloads just fine the first time so I think it may be some cooldown with user requests. – JewishBanana Mar 20 '22 at 08:19

0 Answers0