【发布时间】:2015-05-17 21:18:26
【问题描述】:
我正在尝试使用 volley 实现登录,如下所示:
public static JSONObject register(RequestQueue requestQueue, String url, HashMap<String, String> params) {
RequestFuture<JSONObject> requestFuture = RequestFuture.newFuture();
CustomRequest customRequest = new CustomRequest(Request.Method.POST,url,params,requestFuture,requestFuture);
JSONObject response = null;
requestQueue.add(customRequest);
try {
response = requestFuture.get(30000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
L.m(e + "");
} catch (ExecutionException e) {
L.m(e + "");
} catch (TimeoutException e) {
L.m(e + "");
}
return response;
}
但是每当我发送请求时,我都会得到空值作为响应。 Web api 调用有效,它创建了用户,但如果出现重复用户名等错误,我无法获得 json 结果。
参数是:
网址:http://localhost:13480/api/Account/Register 哈希图:(作为json):
{ "电子邮件": "admin@admin", "密码": "密码 12!", “确认密码”:“密码 12!” }
自定义请求在这里: Volley - POST/GET parameters 所以我无法弄清楚出了什么问题。有什么帮助吗?
【问题讨论】:
-
查看我的答案,它解释了你的代码有什么问题。
-
谢谢,我去看看试试。
-
是的,它有所帮助,但在我的情况下它有点复杂,我有一些额外的抽象层。我会弄清楚的:)
-
好的,现在我明白了,实际上我可以在登录时获得响应,但在注册时,因为我尝试使用相同的用户名注册,我收到 400 错误请求,但我无法获得 json 格式的结果。