@@ -40,20 +40,31 @@ public NativeHttpClient(int maxRetryTimes) {
4040
4141 public ResponseWrapper sendGet (String url , String params ,
4242 String authCode ) throws APIConnectionException , APIRequestException {
43- return sendRequest (url , params , RequestMethod .GET , authCode );
43+ return sendRequest (url , params , RequestMethod .GET , authCode , null );
4444 }
4545
4646 public ResponseWrapper sendPost (String url , String content ,
4747 String authCode ) throws APIConnectionException , APIRequestException {
48- return sendRequest (url , content , RequestMethod .POST , authCode );
48+ return sendRequest (url , content , RequestMethod .POST , authCode , null );
4949 }
5050
51+ public ResponseWrapper sendGet (String url , String params ,
52+ String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
53+ return sendRequest (url , params , RequestMethod .GET , authCode , proxy );
54+ }
55+
56+ public ResponseWrapper sendPost (String url , String content ,
57+ String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
58+ return sendRequest (url , content , RequestMethod .POST , authCode , proxy );
59+ }
60+
61+
5162 public ResponseWrapper sendRequest (String url , String content ,
52- RequestMethod method , String authCode ) throws APIConnectionException , APIRequestException {
63+ RequestMethod method , String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException {
5364 ResponseWrapper response = null ;
5465 for (int retryTimes = 0 ; ; retryTimes ++) {
5566 try {
56- response = _sendRequest (url , content , method , authCode );
67+ response = _sendRequest (url , content , method , authCode , proxy );
5768 break ;
5869 } catch (SocketTimeoutException e ) {
5970 if (KEYWORDS_READ_TIMED_OUT .equals (e .getMessage ())) {
@@ -72,7 +83,7 @@ public ResponseWrapper sendRequest(String url, String content,
7283 }
7384
7485 private ResponseWrapper _sendRequest (String url , String content ,
75- RequestMethod method , String authCode ) throws APIConnectionException , APIRequestException ,
86+ RequestMethod method , String authCode , HttpProxy proxy ) throws APIConnectionException , APIRequestException ,
7687 SocketTimeoutException {
7788 LOG .debug ("Send request to - " + url );
7889 if (null != content ) {
@@ -86,7 +97,16 @@ private ResponseWrapper _sendRequest(String url, String content,
8697
8798 try {
8899 URL aUrl = new URL (url );
89- conn = (HttpURLConnection ) aUrl .openConnection ();
100+
101+ if (null != proxy ) {
102+ conn = (HttpURLConnection ) aUrl .openConnection (proxy .getProxy ());
103+ if (proxy .isAuthenticationNeeded ()) {
104+ conn .addRequestProperty ("Proxy-Authorization" , proxy .getProxyAuthorization ());
105+ }
106+ } else {
107+ conn = (HttpURLConnection ) aUrl .openConnection ();
108+ }
109+
90110 conn .setConnectTimeout (DEFAULT_CONNECTION_TIMEOUT );
91111 conn .setReadTimeout (DEFAULT_READ_TIMEOUT );
92112 conn .setUseCaches (false );
0 commit comments