Uygulamalarınızda kullanmak üzere örnek kod bloglarına buradan erişebilirsiniz.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class ApiExplorer { public static void main(String[] args) throws IOException { StringBuilder urlBuilder = new StringBuilder("https://api.yapikredi.com.tr/api/investmentrates/v1/currencyRates"); URL url = new URL(urlBuilder.toString()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "YOUR TOKEN"); System.out.println("Response code: " + conn.getResponseCode()); BufferedReader rd; if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) { rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); } else { rd = new BufferedReader(new InputStreamReader(conn.getErrorStream())); } StringBuilder sb = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); conn.disconnect(); System.out.println(sb.toString()); } }
var xhr = new XMLHttpRequest(); var url = 'https://api.yapikredi.com.tr/api/investmentrates/v1/currencyRates'; xhr.open('GET', url); xhr.setRequestHeader('Authorization', 'YOUR TOKEN'); xhr.onreadystatechange = function () { if (this.readyState == 4) { alert('Status: '+this.status+'\nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'\nBody: '+this.responseText); } }; xhr.send('');