-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathHttpClientTest.java
More file actions
42 lines (31 loc) · 1.19 KB
/
HttpClientTest.java
File metadata and controls
42 lines (31 loc) · 1.19 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
package test;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpClientTest {
public static void main(String[] argv) throws IOException {
final String WS_URL = argv[0];
URL url;
HttpURLConnection connection;
url = new URL(WS_URL + "/vets.html");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
System.out.println(connection.getResponseCode());
url = new URL(WS_URL + "/oups");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
System.out.println(connection.getResponseCode());
url = new URL(WS_URL + "/owners/new");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
String data = "firstName=John&lastName=Doe&address=Ample+Street&city=London&telephone=1234567891";
OutputStream os = connection.getOutputStream();
byte[] input = data.getBytes("utf-8");
os.write(input, 0, input.length);
System.out.println(connection.getResponseCode());
}
}