这是我的注册代码,当我在android中点击api时,总是收到400错误的响应请求,但在邮递员中,我得到200响应,这是我的错。请帮忙。这是我的控制器代码。
其验证注册数据并保存。
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);
}
}
当我在邮递员中调用相同的功能时,它工作正常,但是尝试使用android时,即使我的代码中的任何地方都没有响应400,我仍然收到400错误的请求。
答案 0 :(得分:0)
获得400的原因是您试图将不允许的字符(例如(@))传递给CodeIgniter,而不对其进行编码。
为了解决此问题,请尝试对来自Android端的输入进行编码
或启用Code Igniter配置中的一些特殊字符,例如注册电子邮件中使用的(@),...。
$config['permitted_uri_chars']