Welcome Guest, Not a member yet? Register   Sign In
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":"[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.
Reply
#2

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

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply
#3

(This post was last modified: 01-15-2020, 01:00 PM by jreklund.)

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




Theme © iAndrew 2016 - Forum software by © MyBB