凌空网址错误-如何解决?

时间:2019-05-29 04:03:22

标签: android android-volley

当我单击登录时,我遇到了Java Volley的问题

  private void Login(){

    String url = "api.matraindonesia.com/login";
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if (response.trim().equals("success")){
                Toast.makeText(getApplicationContext(),"Login Successfully!",Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(),"Login Failed!",Toast.LENGTH_LONG).show();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(),"this error:"+ error.toString(),Toast.LENGTH_LONG).show();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            Map<String, String> params = new HashMap<>();
            params.put("email",etEmail.getText().toString().trim());
            params.put("password",etPassword.getText().toString().trim());

            return super.getParams();
        }
    };
    requestQueue.add(stringRequest);
}
  

com.android.volley.VolleyError:java.lang.RuntimeException:错误的网址

1 个答案:

答案 0 :(得分:1)

您需要在开头使用http://https://url

String url = "http://api.matraindonesia.com/login";

,或者您的服务器是否使用 SSL

String url = "https://api.matraindonesia.com/login";