5252 */
5353public class NIP24Client {
5454
55- public final static String VERSION = "1.3.9 " ;
55+ public final static String VERSION = "1.4.0 " ;
5656
5757 public final static String PRODUCTION_URL = "https://www.nip24.pl/api" ;
5858 public final static String TEST_URL = "https://www.nip24.pl/api-test" ;
@@ -1068,7 +1068,7 @@ public KRSData getKRSSection(Number type, String number, int section)
10681068 String url = (this .url .toString () + "/get/krs/current/" + suffix + "/" + section );
10691069
10701070 // prepare request
1071- byte [] b = get (url );
1071+ byte [] b = get (url , "application/json" );
10721072
10731073 if (b == null ) {
10741074 set (Error .CLI_CONNECT );
@@ -1268,11 +1268,12 @@ private ObjectMapper getObjectMapper()
12681268
12691269 /**
12701270 * Przygotowanie nagłówka z danymi do autoryzacji zapytania
1271+ * @param headers obiekt z nagłówkami HTTP
12711272 * @param method metoda HTTP
12721273 * @param url docelowy adres URL
12731274 * @return nagłówki HTTP lub null
12741275 */
1275- private Properties auth (String method , URL url )
1276+ private boolean auth (Properties headers , String method , URL url )
12761277 {
12771278 try {
12781279 // prepare auth header
@@ -1291,21 +1292,19 @@ private Properties auth(String method, URL url)
12911292 String mac = getMac (str );
12921293
12931294 if (mac == null ) {
1294- return null ;
1295+ return false ;
12951296 }
12961297
12971298 // prepare request
1298- Properties p = new Properties ();
1299-
1300- p .setProperty ("Authorization" , "MAC id=\" " + id + "\" , ts=\" " + ts + "\" , nonce=\" "
1299+ headers .setProperty ("Authorization" , "MAC id=\" " + id + "\" , ts=\" " + ts + "\" , nonce=\" "
13011300 + nonce + "\" , mac=\" " + mac + "\" " );
13021301
1303- return p ;
1302+ return true ;
13041303 }
13051304 catch (Exception ignored ) {
13061305 }
13071306
1308- return null ;
1307+ return false ;
13091308 }
13101309
13111310 /**
@@ -1320,9 +1319,10 @@ private void userAgent(Properties headers)
13201319 /**
13211320 * Metoda HTTP GET
13221321 * @param url adres URL
1322+ * @param mimetype typ MIME odpowiedzi (application/xml lub application/json)
13231323 * @return pobrana odpowiedź lub null
13241324 */
1325- private byte [] get (String url )
1325+ private byte [] get (String url , String mimetype )
13261326 {
13271327 boolean set = false ;
13281328
@@ -1343,10 +1343,12 @@ private byte[] get(String url)
13431343 set = true ;
13441344 }
13451345
1346- // auth
1347- Properties headers = auth ("GET" , u );
1348-
1349- if (headers == null ) {
1346+ // headers
1347+ Properties headers = new Properties ();
1348+
1349+ headers .setProperty ("Accept" , mimetype );
1350+
1351+ if (!auth (headers , "GET" , u )) {
13501352 return null ;
13511353 }
13521354
@@ -1420,6 +1422,16 @@ else if (url.toLowerCase().startsWith("http://")) {
14201422 return null ;
14211423 }
14221424
1425+ /**
1426+ * Metoda HTTP GET
1427+ * @param url adres URL
1428+ * @return pobrana odpowiedź lub null
1429+ */
1430+ private byte [] get (String url )
1431+ {
1432+ return get (url , "application/xml" );
1433+ }
1434+
14231435 /**
14241436 * Odczyt zawartosci calego strumienia do tablicy
14251437 * @param stream strumien wejsciowy
0 commit comments