Using AQuery library with PUT and StringEntity (String) query

I am using the AndroidQuery (AQuery) library for Android, and I need to create a PUT request with the StringEntity entity (some string).

My code, what's wrong? Your suggestions? I tried using without ".header (" _ method "," PUT ")"

HttpEntity entity = null; try { entity = new StringEntity(stringData, HTTP.UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Map<String, Object> params = new HashMap<String, Object>(); params.put(AQuery.POST_ENTITY, entity); AQuery aq = new AQuery(this); aq.progress(pDialog).ajax(url, params, String.class, new AjaxCallback<String>() { @Override public void callback(String url, String json, AjaxStatus status) { if(status.getCode() == 200) { } else { } } }.header("Content-Type", "application/x-www-form-urlencoded") .header("_method", "PUT")); 
+4
source share
2 answers

It is a little hidden, but AjaxCallback has a private method field (and the corresponding typesetter) used to determine which HTTP method to use. The default is METHOD_DETECT , which tries to figure out what to use, and when you add parameters, it will consider it POST.

So, instead of:

 .header("_method", "PUT")); 

Using

 .method(AQuery.METHOD_PUT) 

(Link: https://github.com/androidquery/androidquery/blob/master/src/com/androidquery/callback/AbstractAjaxCallback.java#L280 )

+8
source

AndroidQuery does not support PUT and DELETE queries in general. :( Sad.

-4
source

All Articles