88
99import java .io .*;
1010import java .net .HttpURLConnection ;
11+ import java .net .MalformedURLException ;
1112import java .net .URL ;
1213import java .nio .charset .StandardCharsets ;
1314import java .util .Arrays ;
@@ -49,6 +50,7 @@ public static String downloadFile(String fileURL, String saveDir) throws IOExcep
4950 public static String downloadFile (String fileURL , String saveDir , String name ) throws IOException {
5051 URL url = new URL (fileURL .replace (" " , "%20" ));
5152 HttpURLConnection httpConn = (HttpURLConnection ) url .openConnection ();
53+ httpConn .addRequestProperty ("User-Agent" , "Mozilla/5.0" );
5254 int responseCode = httpConn .getResponseCode ();
5355 String saveFilePath = null ;
5456
@@ -160,7 +162,7 @@ public static Object readJsonFromUrl(String url) {
160162
161163 public static Object readJsonFromUrl (String url , boolean printError ) {
162164 JSONParser parser = new JSONParser ();
163- try (InputStream is = new URL (url ). openStream ( )) {
165+ try (InputStream is = readStreamFromUrl (url )) {
164166 BufferedReader rd = new BufferedReader (new InputStreamReader (is , StandardCharsets .UTF_8 ));
165167 String jsonText = readAll (rd );
166168 return parser .parse (jsonText );
@@ -170,6 +172,12 @@ public static Object readJsonFromUrl(String url, boolean printError) {
170172 }
171173 }
172174
175+ private static InputStream readStreamFromUrl (String url ) throws IOException {
176+ HttpURLConnection httpcon = (HttpURLConnection ) new URL (url ).openConnection ();
177+ httpcon .addRequestProperty ("User-Agent" , "Mozilla/5.0" );
178+ return httpcon .getInputStream ();
179+ }
180+
173181 public static boolean isMCVersionValid (String ver ) {
174182 String [] splitted = ver .replace ("-Snapshot" , "" ).split ("\\ ." );
175183 if (splitted .length > 3 ) return false ;
0 commit comments