Android 获取409错误无法解决如何解决
E/Volley:[19528]基本网络。性能请求:的意外响应代码409 如果用户已经注册,并且otp不正确,我有一些代码可以发出警报,但是在注册时,如果输入otp不正确或者用户已经注册,则警报不会出现。问题是什么?我拿不到它 //注册用户(电话、otp、全名、电子邮件、密码、设备id)Android 获取409错误无法解决如何解决,android,exception,error-handling,runtime-error,android-volley,Android,Exception,Error Handling,Runtime Error,Android Volley,E/Volley:[19528]基本网络。性能请求:的意外响应代码409 如果用户已经注册,并且otp不正确,我有一些代码可以发出警报,但是在注册时,如果输入otp不正确或者用户已经注册,则警报不会出现。问题是什么?我拿不到它 //注册用户(电话、otp、全名、电子邮件、密码、设备id) private void registerUser(最终字符串电话、最终字符串otp、最终字符串全名、最终字符串电子邮件、最终字符串密码、最终字符串设备id) { Log.e(标签“otp12”+otp11);
private void registerUser(最终字符串电话、最终字符串otp、最终字符串全名、最终字符串电子邮件、最终字符串密码、最终字符串设备id)
{
Log.e(标签“otp12”+otp11);
String tag_String_req=“req_register”;
Map params=新的HashMap();
参数put(“内容类型”、“应用程序/json”);
参数put(“电话”,电话);
参数put(“otp”,otp);
参数put(“全名”,全名);
参数put(“电子邮件”,电子邮件);
参数put(“密码”,密码);
参数put(“设备id”,设备id);
JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.POST,
AppConfig.Base_Url+AppConfig.App_api+AppConfig.Url_寄存器,新JSONObject(参数),
新的Response.Listener()
{
@凌驾
公共void onResponse(JSONObject response1){
Log.d(标记,“寄存器响应:+response1.toString());
试一试{
JSONObject jObj=新的JSONObject(String.valueOf(response1));
字符串响应=jObj.getString(“代码”);
字符串状态=jObj.getString(“状态”);
字符串消息=jObj.getString(“消息”);
Log.e(标签,“r2222”+响应);
Log.e(标签“status1:”+状态);
Log.e(标签,“消息”+消息);
if(status!=null&&status.equals(“true”)){
启动屏幕();
Log.e(标签“123”+全名);
Log.e(标签,“状态:”+状态);
Log.e(标签“paswword:”+密码);
Log.e(标签“response2163123:+response”);
}else if(status!=null&&message.equals(“用户已注册”))
{
AlertDialog.Builder=新建AlertDialog.Builder(RegisterActivity.this);
builder.setTitle(“注册错误”);
setMessage(“您已经向FeeDeposit注册。请单击“确定”登录”);
setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
意向意向=新意向(RegisterActivity.this,LoginActivityWithoutSharedPreference.class);
星触觉(意向);
}
});
AlertDialog AlertDialog=builder.create();
alertDialog.show();
}
else if(status!=null&&message.equals(“无效otp”))
{
AlertDialog AlertDialog=新建AlertDialog.Builder(RegisterActivity.this,R.style.MyDialogTheme).create();
//设置对话框标题
alertDialog.setTitle(“OTP”);
//设置对话框消息
alertDialog.setMessage(“无效OTP”);
//将图标设置为对话框
//alertDialog.setIcon(R.drawable.tick);
//设置OK按钮
alertDialog.setButton(“好的”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//在此处编写代码,以便在对话框关闭后执行
//Toast.makeText(getApplicationContext(),“您单击了OK”,Toast.LENGTH\u SHORT.show();
}
});
alertDialog.show();
}
}捕获(JSONException e){
e、 printStackTrace();
//Toast.makeText(getApplicationContext(),“Json错误:+e.getMessage(),Toast.LENGTH_LONG).show();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
if(TimeoutError的错误实例| | NoConnectionError的错误实例){
AlertDialog AlertDialog=新建AlertDialog.Builder(RegisterActivity.this,R.style.MyDialogTheme).create();
//设置对话框标题
alertDialog.setTitle(“网络/连接错误”);
//设置对话框消息
alertDialog.setMessage(“Internet连接不良或服务器响应时间过长。请稍后再试。谢谢。”);
//将图标设置为对话框
//alertDialog.setIcon(R.drawable.tick);
//设置OK按钮
alertDialog.setButton(“好的”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//在此处编写代码,以便在对话框关闭后执行
//Toast.makeText(getApplicationContext(),“您单击了OK”,Toast.LENGTH\u SHORT.show();
}
});
//显示警报消息
alertDialog.show();
//Log.e(标记,“注册错误:+Error.getMessage());
/*Toast.makeText(公司)
private void registerUser(final String phone,final String otp,final String fullname,final String email, final String password, final String device_id )
{
Log.e(TAG, "otp12 " +otp11);
String tag_string_req = "req_register";
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json");
params.put("phone",phone);
params.put("otp",otp);
params.put("fullname", fullname);
params.put("email",email);
params.put("password",password);
params.put("device_id", device_id);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
AppConfig.Base_Url+AppConfig.App_api+AppConfig.URL_REGISTER, new JSONObject(params),
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response1) {
Log.d(TAG, "Register Response: " + response1.toString());
try {
JSONObject jObj = new JSONObject(String.valueOf(response1));
String response = jObj.getString("code");
String status =jObj.getString("status");
String message= jObj.getString("message");
Log.e(TAG, "r2222" + response);
Log.e(TAG, "status1: " + status);
Log.e(TAG,"Message"+message);
if (status!=null && status.equals("true")) {
launchAgeScreen();
Log.e(TAG, "123" + fullname);
Log.e(TAG, "status: " + status);
Log.e(TAG, "paswword: " + password);
Log.e(TAG, "response2163123: " + response);
}else if (status!=null && message.equals("user is already register"))
{
AlertDialog.Builder builder =new AlertDialog.Builder(RegisterActivity.this);
builder.setTitle("Registration Error");
builder.setMessage("You have already registered with FeeDeposit. Please click Okay to Login");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(RegisterActivity.this,LoginActivityWithoutSharedPreference.class);
startActivity(intent);
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
else if (status!=null && message.equals("invalid otp"))
{
AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();
// Setting Dialog Title
alertDialog.setTitle("OTP ");
// Setting Dialog Message
alertDialog.setMessage("Invalid OTP");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Setting OK Button
alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
// Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
}
} catch (JSONException e) {
e.printStackTrace();
//Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();
// Setting Dialog Title
alertDialog.setTitle("Network/Connection Error");
// Setting Dialog Message
alertDialog.setMessage("Internet Connection is poor OR The Server is taking too long to respond.Please try again later.Thank you.");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Setting OK Button
alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
// Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
// Showing Alert Message
alertDialog.show();
// Log.e(TAG, "Registration Error: " + error.getMessage());
/*Toast.makeText(context,
context.getString(R.string.error_network_timeout),
Toast.LENGTH_LONG).show();*/
} /*else if (error instanceof AuthFailureError) {
//TODO
} else if (error instanceof ServerError) {
//TODO
} else if (error instanceof NetworkError) {
//TODO
} else if (error instanceof ParseError) {
//TODO
}
*/
}
}) /*{
@Override
protected Map<String, String> getParams() throws AuthFailureError{
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json");
params.put("phone",phone);
params.put("otp",otp);
params.put("fullname", fullname);
params.put("email",email);
params.put("password",password);
params.put("device_id", device_id);
return params;
}
}*/;
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
try {
ProviderInstaller.installIfNeeded(getApplicationContext());
} catch (GooglePlayServicesRepairableException e) {
// Indicates that Google Play services is out of date, disabled, etc.
// Prompt the user to install/update/enable Google Play services.
GooglePlayServicesUtil.showErrorNotification(e.getConnectionStatusCode(), getApplicationContext());
// Notify the SyncManager that a soft error occurred.
//final SyncResult syncResult = null;
//syncResult.stats.numIOExceptions++;
//Toast.makeText(getApplicationContext(), "Sync", Toast.LENGTH_LONG).show();
return;
} catch (GooglePlayServicesNotAvailableException e) {
// Indicates a non-recoverable error; the ProviderInstaller is not able
// to install an up-to-date Provider.
// Notify the SyncManager that a hard error occurred.
//syncResult.stats.numAuthExceptions++;
// Toast.makeText(getApplicationContext(), "Sync12", Toast.LENGTH_LONG).show();
return;
}
HttpStack stack = null;
try {
stack = new HurlStack(null, new TLSSocketFactory());
} catch (KeyManagementException e) {
e.printStackTrace();
Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
stack = new HurlStack();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
stack = new HurlStack();
}
Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);
// AppController.getInstance().addToRequestQueue(getApplicationContext(),stack);
requestQueue = Volley.newRequestQueue(getApplicationContext(), stack);
} else {
requestQueue = Volley.newRequestQueue(getApplicationContext());
//AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);
// Adding request to request queue
//
//
//
//
//
//AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}