1

如何使用这个 android ajax 查询来发出带有参数的 http post 请求?

    String url = "http://www.mysitecom/MyService.asmx/GetJson";

    // I want to add an string parameter to this query and make it HTTP POST
    aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {

            @Override
            public void callback(String url, JSONObject json, AjaxStatus status) {                                                
                    if(json != null){                                
                            //successful ajax call, show status code and json content
                            Toast.makeText(aq.getContext(), status.getCode() + ":" +                   json.toString(), Toast.LENGTH_LONG).show();                        
                    }else{                                
                            //ajax error, show error code
                            Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show();
                    }
            }
    });
4

1 回答 1

2

我找到了答案:

public void async_post(){

//do a twiiter search with a http post

String url = "http://search.twitter.com/search.json";

Map<String, Object> params = new HashMap<String, Object>();
params.put("q", "androidquery");

aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

    @Override
    public void callback(String url, JSONObject json, AjaxStatus status) {

        showResult(json);

    }
});

}

于 2013-12-17T11:24:30.693 回答