【问题标题】:consume Asp.net MVC api from android volley从 android volley 使用 Asp.net MVC api
【发布时间】:2015-03-11 12:50:54
【问题描述】:

我正在尝试从我的 android 应用程序中使用 MVC 4 api 我正在使用 Volley 库,它可以很好地从服务器获取数据 问题是当我尝试将数据发送到 Web 服务时,我理解它应该通过使用 post Method 和 JsonObjectRequest 来完成

我在 MVC Api 中的方法是:

public class ItemController : ApiController
{
 public IEnumerable<string> Post(List<string> val)
        {

            return val;
        }
}

对于截击:

    String tag_string_req = "req_login";
    Map<String, String> params = new HashMap<>();
    params.put("email", "S@b.Com");
    params.put("username", "basheq");
    JsonObjectRequest req = new JsonObjectRequest(Method.POST , 
    AppConfig.URL_REGISTER, new JSONObject(params),new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d(TAG, "Login Response: " + jsonObject.toString());
            }
        }
      , new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(TAG, "Login Error: " + error.getMessage());
            }
        });
    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req, tag_string_req);

但我一直得到 null 作为响应,看起来 api 没有解析参数。 怎么了 ?? ,这是正确的方法还是有更好的方法??

【问题讨论】:

    标签: android asp.net-mvc android-volley


    【解决方案1】:

    主要问题是我将列表设置为参数,由于某种原因它不起作用 解决方案是将输入参数包装到一个类中,当然还要更改 json 结构以对应于该类

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 2021-10-13
      相关资源
      最近更新 更多