我在 Volley 请求中的响应总是进入 Error Listener
My response in Volley request always get into Error Listener
我正在使用 volly 进行 json 响应,这是我的 java 代码,我尝试了所有方法,但无法在其中找到错误。它总是转到错误 Listener.i 真的不知道为什么我的回复转到错误侦听器任何人帮助我提前感谢
private void userLoign() {
name = Name_Et.getText().toString();
email = Email_Et.getText().toString();
password = Password_Et.getText().toString();
Toast.makeText(MainActivity.this, "enter in userlogin", Toast.LENGTH_SHORT).show();
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String URL = "added-platters.000webhostapp.com/application/index.php";
Toast.makeText(MainActivity.this, "enter in Volley", Toast.LENGTH_SHORT).show();
StringRequest myReq = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
int success = jObj.getInt("value");
Log.e("value in success", String.valueOf(success));
Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Log.i("myTag", e.toString());
Toast.makeText(MainActivity.this, "Parsing error", Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("myTag", error.toString());
Toast.makeText(MainActivity.this, "Server Error", Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "Register");
params.put("name", name);
params.put("email", email);
params.put("password", password);
params.put("lat", "1234");
params.put("log", "1234");
return params;
}
};
myReq.setRetryPolicy(new DefaultRetryPolicy(
20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
));
myReq.setShouldCache(false);
queue.add(myReq);
}
这是我在 php
中的 json 回复
{"value":"Record Inserted Successfully"}
问题是 URL 未指定协议
String URL = "added-platters.000webhostapp.com/application/index.php";
到
String URL = "http://added-platters.000webhostapp.com/application/index.php";
我正在使用 volly 进行 json 响应,这是我的 java 代码,我尝试了所有方法,但无法在其中找到错误。它总是转到错误 Listener.i 真的不知道为什么我的回复转到错误侦听器任何人帮助我提前感谢
private void userLoign() {
name = Name_Et.getText().toString();
email = Email_Et.getText().toString();
password = Password_Et.getText().toString();
Toast.makeText(MainActivity.this, "enter in userlogin", Toast.LENGTH_SHORT).show();
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String URL = "added-platters.000webhostapp.com/application/index.php";
Toast.makeText(MainActivity.this, "enter in Volley", Toast.LENGTH_SHORT).show();
StringRequest myReq = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
int success = jObj.getInt("value");
Log.e("value in success", String.valueOf(success));
Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Log.i("myTag", e.toString());
Toast.makeText(MainActivity.this, "Parsing error", Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("myTag", error.toString());
Toast.makeText(MainActivity.this, "Server Error", Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "Register");
params.put("name", name);
params.put("email", email);
params.put("password", password);
params.put("lat", "1234");
params.put("log", "1234");
return params;
}
};
myReq.setRetryPolicy(new DefaultRetryPolicy(
20000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
));
myReq.setShouldCache(false);
queue.add(myReq);
}
这是我在 php
中的 json 回复{"value":"Record Inserted Successfully"}
问题是 URL 未指定协议
String URL = "added-platters.000webhostapp.com/application/index.php";
到
String URL = "http://added-platters.000webhostapp.com/application/index.php";