我正在尝试创建一个用户登录页面,我在尝试注册时收到此错误。我猜Json对象部分存在问题。我试图在论坛中搜索其他答案但似乎没有解决我的问题。请你帮我解决这个问题。谢谢你的提前。
public void registercheck(final String name, final String email, final String password) {
String tag_req = "Register_request";
pdialog.setMessage("Registering ...");
showDialog();
StringRequest strR = new StringRequest(Request.Method.POST, Appconfig.LOGIN_URL, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
hidedialog();
try {
JSONObject jsp = new JSONObject(s);
boolean error = jsp.getBoolean("error");
if (!error) {
String uid = jsp.getString("uid");
JSONObject user = jsp.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user.getString("created_at");
db.addUser(name, email, uid, created_at);
session.setLogin(true);
Intent i = new Intent(Register.this, MainActivity.class);
startActivity(i);
finish();
} else {
String error_msg = jsp.getString("error_msg");
Toast.makeText(Register.this, error_msg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.e(TAG, volleyError.getMessage());
}
}) {
@Override
public Map<String, String> getParams() {
Map<String, String> p = new HashMap<String, String>();
p.put("name", name);
p.put("tag", "register");
p.put("email", email);
p.put("password", password);
return p;
我的日志猫
15.407 11021-11440/example.com.login E/Volley﹕ [2407] BasicNetwork.performRequest: Unexpected response code 500 for http://busappandroid.gear.host/
答案 0 :(得分:2)
添加标题Content-Type - text / html。我试图从邮递员休息客户端调用你的api没有标题,在将标题添加到api得到结果200状态确定后会给出错误500
答案 1 :(得分:1)
myReq.setRetryPolicy(new DefaultRetryPolicy(10000,0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
在排队添加请求之前添加此行。
这是最小重试次数。默认值为1。