CodeIgniter Forums
Unable to get the json values in from react-native to codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Unable to get the json values in from react-native to codeigniter (/showthread.php?tid=75229)



Unable to get the json values in from react-native to codeigniter - Imran Khan - 01-15-2020

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":"[email protected]","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.


RE: Unable to get the json values in from react-native to codeigniter - nc03061981 - 01-15-2020

The first, you make a get from react native, if it okie, and then you can post it


RE: Unable to get the json values in from react-native to codeigniter - jreklund - 01-15-2020

If it truly sends it into php://input stream you can get that data like this:
https://codeigniter.com/user_guide/libraries/input.html?#using-the-php-input-stream

$this->input->raw_input_stream;