forked from singh387/Madhacks2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.java
73 lines (62 loc) · 1.99 KB
/
requests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.*;
/*import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
*/
public class requests {
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) throws Exception{
requests http = new requests();
System.out.println("Testing get");
http.get();
System.out.println("Testing send");
http.send();
}
public String helper(String key[][],String url)
{
String finalURL = url+"?";
for(String row[]:key)
{
finalURL=finalURL+row[0]+"="+row[1]+"&";
}
finalURL=finalURL.substring(0, finalURL.length()-1);
return finalURL;
}
private void get() throws Exception{
//url
//user: "bob"
//son: "joe"
//url?user=bob&son=joe
URL url = new URL("https://open-ic.epic.com/FHIR/api/FHIR/DSTU2/Patient/Tbt3KuCY0B5PSrJvCu2j-PlK.aiHsu2xUjUM8bWpetXoB");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("accept","application/json");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
public void send() throws Exception{
}
}