【发布时间】: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