-3
            $POSTFIELDS = array(
                    'email' => "fodil@usa.com",
                    'phone' => "656565465422",      
        );  
    curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input") . "&" . $POSTFIELDS);

I can't figure what is wrong with this, it doesn't work, I tried many things but can't make it work...

urnenfeld
  • 1,030
  • 9
  • 25
npolio
  • 11
  • 2
  • 2
    What you trying to do? – Dmitry Leiko Nov 29 '19 at 12:34
  • 2
    For one, it looks like you're concatenating a string with an array at the end there - that's a no-no. Search for examples on http_build_query, like here: https://stackoverflow.com/questions/13596799/how-do-i-use-arrays-in-curl-post-requests – Andrew Nov 29 '19 at 12:36
  • i need just integrate file_get_contents("php://input") with $POSTFIELDS on the same CURLOPT_POSTFIELDS – npolio Nov 29 '19 at 12:37

1 Answers1

1

You are passing post fields in a wrong way to the curl. If you are receiving JSON post the use this..

$post = json_decode(file_get_contents('php://input'));

else use normal post array $_POST.

$post = $_POST

then you CURL request will be...

$post['email'] = 'fodil@usa.com';
$post['phone'] = '656565465422';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
Madhav Palshikar
  • 282
  • 4
  • 12