BasicNetwork.performRequest: Unexpected response code 500

Oshaba Samson posted 9 months ago

I am developing an android application and using laravel and mysql as the backend. when I post data from postman to mysql through laravel it goes through. But for android it displays the above error if the create function is there, returns the json data below if create function is not there just like postman. Here is my code Android code

              RequestQueue requestQueue = Volley.newRequestQueue(SignUpActivity.this);
                try {
                    JSONObject jsonBody = new JSONObject();
                    jsonBody.put("email","[email protected]");

                    JsonObjectRequest request_json = new JsonObjectRequest(url,jsonBody,
                            new Response.Listener<JSONObject>() {
                                public void onResponse(JSONObject response) {
                                  Log.i("info", response.toString());
                            }, new Response.ErrorListener() {
                        public void onErrorResponse(VolleyError error) {
                            VolleyLog.e("Error: ", error.getMessage());
                } catch (JSONException e) {

laravel code

 public function signUp(Request $request){
        $success = "Successful";
        $validator = Validator::make($request->all(), [
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:5'

        if ($validator->fails()){
            return response()->json(['error'=>$validator->errors()], 401);


                'email' => $request->get('email'),
                'username' => $request->get('username'),
                'password' => Hash::make($request->get('password')),
                'vCode' => $request->get('vCode')
        }catch (Exception $exception){
            return response()->json(['error', $exception->getMessage()], 300);

         return $request->all();
      //  return response()->json(['success'=> $success], $this->successStatus);

Output from postman and android

    "email": "[email protected]",
    "password": "jawe55rwwmes",
    "username": "john43eeewson",
    "vCode": "983wer54ew23"

Thanks, all answers will be appreciated

slillo replied 9 months ago

Maybe, via postman you're not passing request body as json. Try this in your controller:

$parameters = request()->json();
//access to parameters using $parameters->get("email")

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us