Jan Ovesny :
i need to send some parameters to the API which accept as it seems only GET method...if i join parameters Im unable to send it through GET method and with POST method I'm getting 404 - not found for the call...
already tried different methods of joining parameters to the call but no luck
// Documentation - https://coinmarketcap.com/api/documentation/v1/#section/Quick-Start-Guide
String apiKey = "707e6117-e462-4de3-9748-98ab6a467f0c"; // my temp key feel free to use it
HttpURLConnection urlConnection = null;
URL url = new URL("https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("X-CMC_PRO_API_KEY", apiKey);
Map<String, String> parameters = new HashMap<>();
parameters.put("start", "1");
parameters.put("limit", "5000");
parameters.put("convert", "USD");
urlConnection.setDoOutput(true);
DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream());
out.writeBytes(ParameterStringBuilder.getParamsString(parameters));
out.flush();
out.close();
urlConnection.connect();
int status = urlConnection.getResponseCode();
String message = urlConnection.getResponseMessage();
I would like to have results from API
ortis :
The documentation only mention GET method. Add the parameters as standard HTTP GET parameters:
String apiKey = "707e6117-e462-4de3-9748-98ab6a467f0c";
final String request = "start=1&limit=500&convert=USD";
HttpURLConnection urlConnection = null;
URL url = new URL("https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?" + request);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("X-CMC_PRO_API_KEY", apiKey);
try (BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
{
String line = br.readLine();
while (line != null)
{
System.out.println(line);
line = br.readLine();
}
}