-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_subscriptions.java
37 lines (28 loc) · 1.2 KB
/
get_subscriptions.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.stream.Collectors;
public class get_subscriptions {
public static void main(String[] args) throws IOException {
// Details retrieved from Authentication part.
String userId = "";
String token = "";
URL url = new URL("https://api.smartproxy.com/v1/users/"+userId+"/subscriptions");
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
httpConn.setRequestProperty("User-Agent", "Mozilla/5.0");
httpConn.setRequestProperty ("Authorization", "Token "+token);
httpConn.setRequestMethod("GET");
if (200 <= httpConn.getResponseCode() && httpConn.getResponseCode() <= 299) {
BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
System.out.print(br.lines().collect(Collectors.joining()));
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(httpConn.getErrorStream()));
System.out.print(br.lines().collect(Collectors.joining()));
}
httpConn.disconnect();
}
}