Skip to content

Commit 08e5f52

Browse files
committed
Refactoring HTTP requests, adding PUT & DELETE support.
1 parent cbe1891 commit 08e5f52

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/main/java/fr/rabian/ovhApi/http/HttpRequests.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@ public abstract class HttpRequests {
2121
*
2222
* @param url URL
2323
* @param out StringBuffer to store response in
24+
* @param headers HTTP headers
2425
* @return Response code
2526
* @throws Exception Exception Occuring during the request
2627
*/
27-
public static int sendGet(String url, StringBuffer out) throws Exception {
28+
public static int sendGet(String url, StringBuffer out, List<Header> headers) throws Exception {
2829
return sendWithoutBody(url, "GET", out, null);
2930
}
3031

32+
/**
33+
* DELETE request.
34+
*
35+
* @param url URL
36+
* @param out StringBuffer to store response in
37+
* @param headers HTTP headers
38+
* @return Response code
39+
* @throws Exception Exception Occuring during the request
40+
*/
41+
public static int sendDelete(String url, StringBuffer out, List<Header> headers) throws Exception {
42+
return sendWithoutBody(url, "DELETE", out, null);
43+
}
44+
3145
/**
3246
* Send a request without body (GET, DELETE...)
3347
*
@@ -38,7 +52,7 @@ public static int sendGet(String url, StringBuffer out) throws Exception {
3852
* @return Response code
3953
* @throws Exception Occuring during the request
4054
*/
41-
public static int sendWithoutBody(String url, String method, StringBuffer out, List<Header> headers) throws Exception {
55+
private static int sendWithoutBody(String url, String method, StringBuffer out, List<Header> headers) throws Exception {
4256

4357
URL obj = new URL(url);
4458
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
@@ -65,15 +79,17 @@ public static int sendWithoutBody(String url, String method, StringBuffer out, L
6579
}
6680

6781
/**
68-
* POST request.
82+
* PUT request.
83+
*
6984
* @param url URL
7085
* @param out StringBuffer to store response in
7186
* @param body Request body
87+
* @param headers HTTP headers
7288
* @return Response code
7389
* @throws Exception Occuring during the request
7490
*/
75-
public static int sendPost(String url, StringBuffer out, String body) throws Exception {
76-
return sendPost(url, out, body, null);
91+
public static int sendPut(String url, StringBuffer out, String body, List<Header> headers) throws Exception {
92+
return sendWithBody(url, "PUT", out, body, null);
7793
}
7894

7995
/**

0 commit comments

Comments
 (0)