The type "application / json" prevents sending mail variables

I found that if I try curl PHP POST, postvars are sent fine. As soon as I add an httpheader of type content: application/jsonpostvars will no longer go over. I tried postvars as a JSON string and as a query string.

Code Display:

$ch = curl_init();

$post =  json_encode(array('p1' => 'blahblahblah', 'p2' => json_encode(array(4,5,6))));

$arr = array();
array_push($arr, 'Content-Type: application/json; charset=utf-8');

curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'https://example.com/file.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

curl_exec($ch);
curl_close($ch);
+3
source share
1 answer

Real HTTP mail, which is automatically split into an array using PHP, must be formatted in name = value pairs; the best way to do this in PHP is to use the http_build_query function.

http://ca2.php.net/manual/en/function.http-build-query.php

There is an example that works in the PHP manual using curl:

http://ca2.php.net/manual/en/function.curl-exec.php#98628

, "RAW", . :

JSON PHP

, RAW Json.

<?php

print_r(json_decode(file_get_contents('php://input')));
+5

Source: https://habr.com/ru/post/1792681/


All Articles