带有 HTTP POST 的 Android JSON ajaxQuery

标签 android ajax http post aquery

我如何使用这个 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();
                    }
            }
    });

最佳答案

我找到了答案:

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);

    }
});

关于带有 HTTP POST 的 Android JSON ajaxQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20631969/

相关文章:

在 Gradle 上创建新项目时 Android Studio 卡住了 : Configure Project or Gradle: Resolve Dependencies ':classpath:'

javascript - 与 Codeigniter 和 AJAX 类似的系统

java - RESTEasy 客户端框架身份验证凭据

javascript - 无法从 angularjs 应用程序调用 Web 服务

android - 在 App 中集成 segment.io

php - 如何从mysql中获取数据并存储在android中的Sqlite数据库中

android - Urban-airship + Facebook cordova 插件 android-support-v4 冲突

javascript - 仅应用最后一个单词的 keyup 事件

javascript - 将 PHP 变量传递给 jQuery 时遇到问题

angularjs - 访问 Spotify api 调用响应中的 header