• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to get the json values in from react-native to codeigniter

#1
Hi Everyone,

I am trying to send the email and password through react native but i am unable to get the posted values in codeigniter.

Here is api call from react native

Code:
export const api = async (url, method, body = null, headers = {}) => {

try {
  const endPoint = BASE_URL.concat(url);
  const reqBody = body ? JSON.stringify(body) : null;

  const fetchParams = {method, headers};

  if((method === "POST" || method === "PUT") && !reqBody) {
      throw new Error("Request body required");
  }


  if(reqBody) {
      fetchParams.headers["Content-type"] = "application/json";
      fetchParams.mode =  'cors';
      fetchParams.body = reqBody;
  }

  const fetchPromise = fetch(endPoint, fetchParams);
  const timeOutPromise = new Promise((resolve, reject) => {
      setTimeout(() => {
          reject("Request Timeout");
      }, 3000);
  });

  const response = await Promise.race([fetchPromise, timeOutPromise]);

  return response;
} catch (e) {
  return e;
}}


Datasent is in this form



Code:
{"email":"test@gmail.com","password":"1234"}


In codeigniter i am trying to get like this



Code:
$email = $this->input->post('email');
$password = $this->input->post('password');


Other way i used but nothing is working.like


Code:
$rawData = file_get_contents("php://input");
$postedValue = json_decode($rawData,true);
$postedValue['email'];


Thanks in advance.
Reply

#2
The first, you make a get from react native, if it okie, and then you can post it
Love CI & Thanks CI Teams
Reply

#3
If it truly sends it into php://input stream you can get that data like this:
https://codeigniter.com/user_guide/libra...put-stream

$this->input->raw_input_stream;
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.