-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackpr_tradier.java
49 lines (42 loc) · 1.72 KB
/
hackpr_tradier.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
38
39
40
41
42
43
44
45
46
47
48
49
package com.tradier.webservice.client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
public class GETClient {
public static void main(String[] args) throws ClientProtocolException, IOException {
BufferedReader responseBody = null;
HttpClient client = HttpClientBuilder.create().build();
try {
//Define a HttpGet request
HttpGet request = new HttpGet("https://api.tradier.com/v1/user/profile");
//Set Http Headers
request.addHeader("Accept" , "application/xml");
request.addHeader("Authorization", "Bearer ");
//Invoke the service
HttpResponse response = client.execute(request);
//Verify if the response is valid
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode!=200) {
throw new RuntimeException("Failed with HTTP error code : " + statusCode);
} else {
//If valid, get the response
responseBody = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = responseBody.readLine()) != null) {
System.out.println(line);
}
}
}
catch(Exception e) {
e.printStackTrace();
} finally {
if(responseBody!=null)
responseBody.close();
}
}
}