@@ -115,6 +115,7 @@ public class AsyncHttpClient {
115
115
private ThreadPoolExecutor threadPool ;
116
116
private final Map <Context , List <WeakReference <Future <?>>>> requestMap ;
117
117
private final Map <String , String > clientHeaderMap ;
118
+ private boolean isUrlEncodingEnabled = true ;
118
119
119
120
120
121
/**
@@ -343,6 +344,7 @@ public void setProxy(String hostname, int port) {
343
344
final HttpParams httpParams = this .httpClient .getParams ();
344
345
httpParams .setParameter (ConnRoutePNames .DEFAULT_PROXY , proxy );
345
346
}
347
+
346
348
/**
347
349
* Sets the Proxy by it's hostname,port,username and password
348
350
*
@@ -351,14 +353,14 @@ public void setProxy(String hostname, int port) {
351
353
* @param username the username
352
354
* @param password the password
353
355
*/
354
- public void setProxy (String hostname ,int port ,String username ,String password ){
355
- httpClient .getCredentialsProvider ().setCredentials (
356
- new AuthScope (hostname , port ),
357
- new UsernamePasswordCredentials (username , password ));
356
+ public void setProxy (String hostname , int port , String username , String password ) {
357
+ httpClient .getCredentialsProvider ().setCredentials (
358
+ new AuthScope (hostname , port ),
359
+ new UsernamePasswordCredentials (username , password ));
358
360
final HttpHost proxy = new HttpHost (hostname , port );
359
361
final HttpParams httpParams = this .httpClient .getParams ();
360
362
httpParams .setParameter (ConnRoutePNames .DEFAULT_PROXY , proxy );
361
- }
363
+ }
362
364
363
365
364
366
/**
@@ -501,7 +503,7 @@ public void head(Context context, String url, AsyncHttpResponseHandler responseH
501
503
* @param responseHandler the response handler instance that should handle the response.
502
504
*/
503
505
public void head (Context context , String url , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
504
- sendRequest (httpClient , httpContext , new HttpHead (getUrlWithQueryString (url , params )), null , responseHandler , context );
506
+ sendRequest (httpClient , httpContext , new HttpHead (getUrlWithQueryString (isUrlEncodingEnabled , url , params )), null , responseHandler , context );
505
507
}
506
508
507
509
/**
@@ -516,7 +518,7 @@ public void head(Context context, String url, RequestParams params, AsyncHttpRes
516
518
* the response.
517
519
*/
518
520
public void head (Context context , String url , Header [] headers , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
519
- HttpUriRequest request = new HttpHead (getUrlWithQueryString (url , params ));
521
+ HttpUriRequest request = new HttpHead (getUrlWithQueryString (isUrlEncodingEnabled , url , params ));
520
522
if (headers != null ) request .setHeaders (headers );
521
523
sendRequest (httpClient , httpContext , request , null , responseHandler ,
522
524
context );
@@ -568,7 +570,7 @@ public void get(Context context, String url, AsyncHttpResponseHandler responseHa
568
570
* @param responseHandler the response handler instance that should handle the response.
569
571
*/
570
572
public void get (Context context , String url , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
571
- sendRequest (httpClient , httpContext , new HttpGet (getUrlWithQueryString (url , params )), null , responseHandler , context );
573
+ sendRequest (httpClient , httpContext , new HttpGet (getUrlWithQueryString (isUrlEncodingEnabled , url , params )), null , responseHandler , context );
572
574
}
573
575
574
576
/**
@@ -583,7 +585,7 @@ public void get(Context context, String url, RequestParams params, AsyncHttpResp
583
585
* the response.
584
586
*/
585
587
public void get (Context context , String url , Header [] headers , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
586
- HttpUriRequest request = new HttpGet (getUrlWithQueryString (url , params ));
588
+ HttpUriRequest request = new HttpGet (getUrlWithQueryString (isUrlEncodingEnabled , url , params ));
587
589
if (headers != null ) request .setHeaders (headers );
588
590
sendRequest (httpClient , httpContext , request , null , responseHandler ,
589
591
context );
@@ -802,7 +804,7 @@ public void delete(Context context, String url, Header[] headers, AsyncHttpRespo
802
804
* @param responseHandler the response handler instance that should handle the response.
803
805
*/
804
806
public void delete (Context context , String url , Header [] headers , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
805
- HttpDelete httpDelete = new HttpDelete (getUrlWithQueryString (url , params ));
807
+ HttpDelete httpDelete = new HttpDelete (getUrlWithQueryString (isUrlEncodingEnabled , url , params ));
806
808
if (headers != null ) httpDelete .setHeaders (headers );
807
809
sendRequest (httpClient , httpContext , httpDelete , null , responseHandler , context );
808
810
}
@@ -830,7 +832,20 @@ protected void sendRequest(DefaultHttpClient client, HttpContext httpContext, Ht
830
832
}
831
833
}
832
834
833
- public static String getUrlWithQueryString (String url , RequestParams params ) {
835
+ public void setURLEncodingEnabled (boolean enabled ) {
836
+ this .isUrlEncodingEnabled = enabled ;
837
+ }
838
+
839
+ /**
840
+ * Will encode url, if not disabled, and adds params on the end of it
841
+ *
842
+ * @param url String with URL, should be valid URL without params
843
+ * @param params RequestParams to be appended on the end of URL
844
+ */
845
+ public static String getUrlWithQueryString (boolean isUrlEncodingEnabled , String url , RequestParams params ) {
846
+ if (isUrlEncodingEnabled )
847
+ url = url .replace (" " , "%20" );
848
+
834
849
if (params != null ) {
835
850
String paramString = params .getParamString ();
836
851
if (!url .contains ("?" )) {
0 commit comments