Android工作室凌空错误

时间:2017-01-10 05:42:23

标签: android-volley

您好我想从android studio将用户信息发布到我的数据库,但我收到此错误

  

01-10 06:35:20.606   31347-32713 / com.celeritydigital.instachops.instachops E / Volley:[6032]   BasicNetwork.performRequest:意外的响应代码500   http://www.Sweetcheeks.com/api/auth/signup

我试过过帖子,但是有效。

public class registerActivity extends AppCompatActivity implements View.OnClickListener {

private static final String REGISTER_URL = "http://www.instachops.com/api/auth/signup";

public static final String KEY_FIRSTNAME = "first_name";
public static final String KEY_LASTTNAME= "last_name";
public static final String KEY_EMAIL = "email";
public static final String KEY_PHONE = "phone";
public static final String KEY_PASSWORD = "password";



private EditText firstName;
private EditText lastName;
private EditText emailAddress;
private EditText phone;
private EditText password;


private Button registerSignup;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);


    firstName = (EditText) findViewById(R.id.firstName);
    lastName = (EditText) findViewById(R.id.lastName);
    emailAddress = (EditText) findViewById(R.id.emailAddress);
    password = (EditText) findViewById(R.id.password);
    phone = (EditText) findViewById(R.id.phone);

    registerSignup = (Button) findViewById(R.id.registerSignup);

    registerSignup.setOnClickListener(this);


    //onclick (open splashActivity)

    Button backtosplash = (Button) findViewById(R.id.registerbackbtn);
    backtosplash.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(registerActivity.this, splashActivity.class);
            startActivityForResult(intent, 0);

        }
    });

    //onclick (open splashActivity)

}

private void registerUser() {

    final String firstname = firstName.getText().toString().trim();
    final String lastname = lastName.getText().toString().trim();
    final String emailaddress = emailAddress.getText().toString().trim();
    final String passwordt = password.getText().toString().trim();
    final String phonet = phone.getText().toString().trim();

    StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                    Toast.makeText(registerActivity.this, response, Toast.LENGTH_LONG).show();

                }

            },

            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                    Toast.makeText(registerActivity.this, error.toString(), Toast.LENGTH_LONG).show();

                }
            }){
                @Override
                protected Map<String, String> getParams(){
                    Map<String, String> params = new HashMap<String, String>();

                    params.put(KEY_FIRSTNAME,firstname);
                    params.put(KEY_LASTTNAME,lastname);
                    params.put(KEY_EMAIL,emailaddress);
                    params.put(KEY_PHONE,phonet);
                    params.put(KEY_PASSWORD,passwordt);


                    return params;
                }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

@Override
public void onClick(View v) {
    if(v == registerSignup){
        registerUser();
    }
}
}}

1 个答案:

答案 0 :(得分:0)

尝试在getParams方法之后修改此方法,以便设置内容类型并重试

 @Override
                    public Map<String, String> getHeaders() throws AuthFailureError {
                        Map<String,String> params = new HashMap<String, String>();
                        params.put("Content-Type","application/x-www-form-urlencoded");
                        return params;
                    }