简体   繁体   中英

In codeigniter api I am getting 400 bad request always in android but getting 200 in postman

this is my code for registration I am getting 400 bad request in response always when I hit api in android but in postman i am getting 200 response whats wrong with me. Please Help. Here is my controller code.

its validating registration data and saving it.

public function register_user_get()
{

    $user_data = $_GET['user_details'];

    $user_details_arr = array();

    $user_details_arr = json_decode($user_data);

    $username_exist = $this->apilogin_model->check_username_exists($user_details_arr->username);
    if(!empty($username_exist))
    {
        $response = array(
            'message'=>'Username is already exist',
            'status'=>false
        );

        $this->response($response,200);
    }

    $referred_by = $user_details_arr->referred_by;  //'company';


    if($referred_by == 'company')
    {
        $referral_code = ROOT_REFERRAL_CODE;
        $user = $this->apilogin_model->get_user_details_by_referral_code($referral_code);

        if(empty($user))
        {
            // if referral code in invalid
            $response = array(
                'message'=>'Invalid Referral code',
                'status'=>false
            );
            $this->response($response,200);
        }
    }
    else if($referred_by == "manual")
    {
        $referral_code = $user_details_arr->referral_code;
        $user = $this->apilogin_model->get_user_details_by_referral_code($referral_code);

        if(empty($user))
        {

            $response = array(
                'message'=>'Invalid Referral code',
                'status'=>false
            );
            $this->response($response,200);
        }
    }
    else
    {

    }   


    $parent_id = $user[0]->id;


    $data = array(
        'name' => $user_details_arr->name,
        'username' => $user_details_arr->username,
        'password' => md5($user_details_arr->password),
        'paytm_no' => $user_details_arr->paytm_no,
        'mobile_no' => $user_details_arr->mobile_no,
        'email_id' => $user_details_arr->email_id,
        'parent_id' => $parent_id,
        'referral_code' => $this->generate_code(), // for generate 10 digit unique referral code
        'is_deleted' => 'N',
        'created_at' => date('Y-m-d H:i:s'),
        'updated_at' => date('Y-m-d H:i:s'),
    ); 

    $res = $this->apilogin_model->save_affiliate_data($data); 
    $transaction_data = $this->parent_get($res,$parent_id,LEVEL_FOR_HELP);
    $child_arr = array(
                'sender_id' =>$res,
                'receiver_id' =>COMPANY_ID,
                'status'=>0,
                'created_at' =>date('Y-m_d H:i:s')
            );

    array_push($transaction_data,$child_arr);
    //$this->db->set($transaction_data);

    $this->db->insert_batch(DB_PREFIX.'_transaction', $transaction_data);

    if($res > 0) 
    {
        // if data saved successfully
        $response = array(
            'message'=>'Registered Successfully',
            'status'=>true
        );

        $this->response($response,200);
    }
    else
    {
        // if data doesn't saved successfully
        $response = array(
            'message'=>'Registration Failed',
            'status'=>false
        );

        $this->response($response,200);
    }
}

while I am calling same function in postman it working fine but while trying with android I am getting 400 bad request even I am not responding 400 anywhere in my code.

The reason why you are getting 400 is that you are trying to pass not allowed character such as(@) to CodeIgniter without encoding it.

In order to fix this try to encode the inputs from your android side

Or enable some special character such as (@) which been used in your registration email,... from Code Igniter configuration.

$config['permitted_uri_chars']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM