@@ -47,20 +47,25 @@ public NativeHttpClient(String authCode, int maxRetryTimes, HttpProxy proxy) {
4747
4848 public ResponseWrapper sendGet (String url )
4949 throws APIConnectionException , APIRequestException {
50- return sendRequest (url , null , RequestMethod .GET );
50+ return doRequest (url , null , RequestMethod .GET );
5151 }
5252
53+ public ResponseWrapper sendDelete (String url )
54+ throws APIConnectionException , APIRequestException {
55+ return doRequest (url , null , RequestMethod .DELETE );
56+ }
57+
5358 public ResponseWrapper sendPost (String url , String content )
5459 throws APIConnectionException , APIRequestException {
55- return sendRequest (url , content , RequestMethod .POST );
60+ return doRequest (url , content , RequestMethod .POST );
5661 }
5762
58- public ResponseWrapper sendRequest (String url , String content ,
63+ public ResponseWrapper doRequest (String url , String content ,
5964 RequestMethod method ) throws APIConnectionException , APIRequestException {
6065 ResponseWrapper response = null ;
6166 for (int retryTimes = 0 ; ; retryTimes ++) {
6267 try {
63- response = _sendRequest (url , content , method );
68+ response = _doRequest (url , content , method );
6469 break ;
6570 } catch (SocketTimeoutException e ) {
6671 if (KEYWORDS_READ_TIMED_OUT .equals (e .getMessage ())) {
@@ -78,7 +83,7 @@ public ResponseWrapper sendRequest(String url, String content,
7883 return response ;
7984 }
8085
81- private ResponseWrapper _sendRequest (String url , String content ,
86+ private ResponseWrapper _doRequest (String url , String content ,
8287 RequestMethod method ) throws APIConnectionException , APIRequestException ,
8388 SocketTimeoutException {
8489 LOG .debug ("Send request to - " + url );
@@ -115,16 +120,18 @@ private ResponseWrapper _sendRequest(String url, String content,
115120 conn .setRequestProperty ("Charset" , CHARSET );
116121 conn .setRequestProperty ("Authorization" , _authCode );
117122
118- if (RequestMethod .POST == method ) {
119- conn .setDoOutput (true ); //POST Request
123+ if (RequestMethod .GET == method ) {
124+ conn .setDoOutput (false );
125+ } else if (RequestMethod .DELETE == method ) {
126+ conn .setDoOutput (false );
127+ } else if (RequestMethod .POST == method ) {
128+ conn .setDoOutput (true );
120129 conn .setRequestProperty ("Content-Type" , CONTENT_TYPE_JSON );
121130 byte [] data = content .getBytes (CHARSET );
122131 conn .setRequestProperty ("Content-Length" , String .valueOf (data .length ));
123132 out = conn .getOutputStream ();
124133 out .write (data );
125134 out .flush ();
126- } else {
127- conn .setDoOutput (false );
128135 }
129136
130137 int status = conn .getResponseCode ();
0 commit comments