5858import org .apache .http .impl .client .DefaultHttpClient ;
5959import org .apache .http .impl .conn .tsccm .ThreadSafeClientConnManager ;
6060import org .apache .http .params .BasicHttpParams ;
61+ import org .apache .http .params .HttpParams ;
6162import org .apache .http .params .HttpConnectionParams ;
6263import org .apache .http .params .HttpProtocolParams ;
6364import org .apache .http .protocol .BasicHttpContext ;
@@ -200,6 +201,17 @@ public void setUserAgent(String userAgent) {
200201 HttpProtocolParams .setUserAgent (this .httpClient .getParams (), userAgent );
201202 }
202203
204+ /**
205+ * Sets the connection time oout. By default, 10 seconds
206+ * @param timeout the connect/socket timeout in milliseconds
207+ */
208+ public void setTimeout (int timeout ){
209+ final HttpParams httpParams = this .httpClient .getParams ();
210+ ConnManagerParams .setTimeout (httpParams , timeout );
211+ HttpConnectionParams .setSoTimeout (httpParams , timeout );
212+ HttpConnectionParams .setConnectionTimeout (httpParams , timeout );
213+ }
214+
203215 /**
204216 * Sets the SSLSocketFactory to user when making requests. By default,
205217 * a new, default SSLSocketFactory is used.
@@ -287,6 +299,23 @@ public void get(Context context, String url, AsyncHttpResponseHandler responseHa
287299 public void get (Context context , String url , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
288300 sendRequest (httpClient , httpContext , new HttpGet (getUrlWithQueryString (url , params )), null , responseHandler , context );
289301 }
302+
303+ /**
304+ * Perform a HTTP GET request and track the Android Context which initiated
305+ * the request with customized headers
306+ *
307+ * @param url the URL to send the request to.
308+ * @param headers set headers only for this request
309+ * @param params additional GET parameters to send with the request.
310+ * @param responseHandler the response handler instance that should handle
311+ * the response.
312+ */
313+ public void get (Context context , String url , Header [] headers , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
314+ HttpUriRequest request = new HttpGet (getUrlWithQueryString (url , params ));
315+ if (headers != null ) request .setHeaders (headers );
316+ sendRequest (httpClient , httpContext , request , null , responseHandler ,
317+ context );
318+ }
290319
291320
292321 //
@@ -335,6 +364,29 @@ public void post(Context context, String url, HttpEntity entity, String contentT
335364 sendRequest (httpClient , httpContext , addEntityToRequestBase (new HttpPost (url ), entity ), contentType , responseHandler , context );
336365 }
337366
367+ /**
368+ * Perform a HTTP POST request and track the Android Context which initiated
369+ * the request. Set headers only for this request
370+ *
371+ * @param context the Android Context which initiated the request.
372+ * @param url the URL to send the request to.
373+ * @param headers set headers only for this request
374+ * @param entity a raw {@link HttpEntity} to send with the request, for
375+ * example, use this to send string/json/xml payloads to a server by
376+ * passing a {@link org.apache.http.entity.StringEntity}.
377+ * @param contentType the content type of the payload you are sending, for
378+ * example application/json if sending a json payload.
379+ * @param responseHandler the response handler instance that should handle
380+ * the response.
381+ */
382+ public void post (Context context , String url , Header [] headers , RequestParams params , String contentType ,
383+ AsyncHttpResponseHandler responseHandler ) {
384+ HttpEntityEnclosingRequestBase request = new HttpPost (url );
385+ if (params != null ) request .setEntity (paramsToEntity (params ));
386+ if (headers != null ) request .setHeaders (headers );
387+ sendRequest (httpClient , httpContext , request , contentType ,
388+ responseHandler , context );
389+ }
338390
339391 //
340392 // HTTP PUT Requests
@@ -372,6 +424,7 @@ public void put(Context context, String url, RequestParams params, AsyncHttpResp
372424
373425 /**
374426 * Perform a HTTP PUT request and track the Android Context which initiated the request.
427+ * And set one-time headers for the request
375428 * @param context the Android Context which initiated the request.
376429 * @param url the URL to send the request to.
377430 * @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}.
@@ -381,7 +434,22 @@ public void put(Context context, String url, RequestParams params, AsyncHttpResp
381434 public void put (Context context , String url , HttpEntity entity , String contentType , AsyncHttpResponseHandler responseHandler ) {
382435 sendRequest (httpClient , httpContext , addEntityToRequestBase (new HttpPut (url ), entity ), contentType , responseHandler , context );
383436 }
384-
437+
438+ /**
439+ * Perform a HTTP PUT request and track the Android Context which initiated the request.
440+ * And set one-time headers for the request
441+ * @param context the Android Context which initiated the request.
442+ * @param url the URL to send the request to.
443+ * @param headers set one-time headers for this request
444+ * @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}.
445+ * @param contentType the content type of the payload you are sending, for example application/json if sending a json payload.
446+ * @param responseHandler the response handler instance that should handle the response.
447+ */
448+ public void put (Context context , String url ,Header [] headers , HttpEntity entity , String contentType , AsyncHttpResponseHandler responseHandler ) {
449+ HttpEntityEnclosingRequestBase request = addEntityToRequestBase (new HttpPut (url ), entity );
450+ if (headers != null ) request .setHeaders (headers );
451+ sendRequest (httpClient , httpContext , request , contentType , responseHandler , context );
452+ }
385453
386454 //
387455 // HTTP DELETE Requests
@@ -406,7 +474,19 @@ public void delete(Context context, String url, AsyncHttpResponseHandler respons
406474 final HttpDelete delete = new HttpDelete (url );
407475 sendRequest (httpClient , httpContext , delete , null , responseHandler , context );
408476 }
409-
477+
478+ /**
479+ * Perform a HTTP DELETE request.
480+ * @param context the Android Context which initiated the request.
481+ * @param url the URL to send the request to.
482+ * @param headers set one-time headers for this request
483+ * @param responseHandler the response handler instance that should handle the response.
484+ */
485+ public void delete (Context context , String url , Header [] headers , AsyncHttpResponseHandler responseHandler ) {
486+ final HttpDelete delete = new HttpDelete (url );
487+ if (headers != null ) delete .setHeaders (headers );
488+ sendRequest (httpClient , httpContext , delete , null , responseHandler , context );
489+ }
410490
411491
412492 // Private stuff
0 commit comments