Почему я получаю 404 здесь, при загрузке частного артефакта репо.
URL url = new URL("https://github.com/anandchakru/private_repo/releases/download/rel_v1/artif-3.0.jar?access_token=myaccesstoken"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); System.out.println(connection.getResponseCode()); //404
и не здесь, при загрузке публичного репо-релизаартефакт?
URL url = new URL("https://github.com/anandchakru/fr/releases/download/1.0/fr.jar"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); System.out.println(connection.getResponseCode()); //200
Примечание: Я могу загрузить https://github.com/anandchakru/private_repo/releases/download/rel_v1/artif-3.0.jar?access_token=myaccesstoken (в браузере в режиме инкогнито / provate_mode).
https://github.com/anandchakru/private_repo/releases/download/rel_v1/artif-3.0.jar?access_token=myaccesstoken
Закончилось следующим:
Accept: application/json
https://api.github.com/repos/anandchakru/private_repo/releases/assets/<asset_id>?access_token=myaccesstoken
код
URL url = new URL("https://api.github.com/repos/anandchakru/private_repo/releases/assets/<asset_id>?access_token=<token>"); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestProperty("Accept", "application/octet-stream"); ReadableByteChannel uChannel = Channels.newChannel(connection.getInputStream()); FileOutputStream foStream = new FileOutputStream("C:/Users/username/artif-3.0.jar"); FileChannel fChannel = foStream.getChannel(); fChannel.transferFrom(uChannel, 0, Long.MAX_VALUE); uChannel.close(); foStream.close(); fChannel.close(); System.out.println(connection.getResponseCode());
Не забудьте закрыть foStream & uChannel.