AQuery POST请求

时间:2013-11-29 15:45:38

标签: android http-post android-query

AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>();
cb.weakHandler(this, callback).url(soapUrl).type(XmlDom.class)
    .header("CustomHeader", "Custom_header_string")
    .header("Content-Type", "application/xml;charset=utf-8");
cb.method(AQuery.METHOD_POST);
HttpEntity entity = new StringEntity(data);
cb.param(AQuery.POST_ENTITY,entity);
cb.setSSF(SelfSignedCertsSSLSocketFactory.getSocketFactory());
aq.sync(cb);

是我的用于向VPN网络上的服务器发送POST请求的Aquery代码。我似乎得到了200响应,因为我得到以下内容,但回调从未被调用。

W/AQuery﹕ response:200

我做错了什么,怎么能找到更多?

1 个答案:

答案 0 :(得分:1)

首先,我将URL设置为callback属性,从未调用过URL,并且从不触发回调。最后,我将URL直接设置为AQuery并正常工作

    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject html, AjaxStatus status) {        
            System.out.println(html);
        }
    };

    AQuery aq = new AQuery(MainActivity88.this);

    cb.header("Authorization", "key=yourkey");
    cb.header("Content-Type", "application/json; charset=utf-8");

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(AQuery.POST_ENTITY, createStringEntity(json));

    cb.params(params);

    aq.ajax("https://yourdomain.com",JSONObject.class, cb);

另请尝试http://loopj.com/android-async-http/