-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_baglanti.java
More file actions
62 lines (47 loc) · 1.5 KB
/
Copy pathapi_baglanti.java
File metadata and controls
62 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/*
* TAHA TANGÜLÜ
* 16260055
*/
public class api_baglanti {
public static void main(String[] args) {
BufferedReader reader;
String line;
StringBuffer responseContent = new StringBuffer();
try {
URL url = new URL("https://api.coindesk.com/v1/bpi/currentprice/BTC.json");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//Request kısımı
connection.setRequestMethod("GET");
connection.setConnectTimeout(2500);
connection.setReadTimeout(3000);
int status = connection.getResponseCode();
System.out.println(status);
if (status > 299) {
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
while ((line = reader.readLine()) != null) {
responseContent.append(line);
}
reader.close();
} else {
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = reader.readLine()) != null) {
responseContent.append(line);
}
reader.close();
}
System.out.println(responseContent.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//connection.disconnect();
}
}
}