No me trabaja el $_POST en el cURL
Publicado por Yoel (199 intervenciones) el 20/10/2020 06:22:53
Hola a todos, tengo la siguiente situación. Estoy haciendo una petición por POST con un cURL a una api pero me está devolviendo vacío. El dato del array que estoy enviando es un json a continuación les dejo el código para ver si me pueden ayudar.
Gracias
Petición sin el POST:
Resultado:
Petición con el POST
Resultado
Gracias
Petición sin el POST:
1
2
3
4
5
6
7
8
9
10
11
12
curl_setopt($ch, CURLOPT_URL, "https://marketplace.api.healthcare.gov/api/v1/versions?apikey=xxxxxxxxxxxxxxxxxxxxx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
Resultado:
1
string(523) "[{"name":"drugs","updated":"2020-06-16T14:10:13Z"},{"name":"npis","updated":"2020-10-13T17:41:51Z"},{"name":"issuers","updated":"2020-09-14T00:11:10Z"},{"name":"pet-seed","updated":"2017-05-23T00:00:00Z"},{"name":"zipcodes","updated":"2020-09-14T00:00:00Z"},{"name":"etl-id","updated":"20200916-210245"},{"name":"coverage","updated":"2020-10-19T19:38:29Z"},{"name":"plan-etl","updated":"2020-09-16T21:13:18.676046Z"},{"name":"plans","updated":"2020-09-14T12:57:58Z"},{"name":"taxonomies","updated":"2019-10-09T16:17:05Z"}] "
Petición con el POST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$ch = curl_init();
$datos = [
"household" => [
"income" => 52000,
"people" => [
[
"age" => 27,
"aptc_eligible" => true,
"gender" => "Female",
"uses_tobacco" => false
]
],
],
"market" => "Individual",
"place" => [
"countyfips" => "37057",
"state" => "NC",
"zipcode" => "27360"
],
"year" => 2020
];
$postdata = json_encode(array('data'=> $datos));
curl_setopt($ch, CURLOPT_URL, "https://marketplace.api.healthcare.gov/api/v1/versions?apikey=xxxxxxxxxxxxxxxxxx");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
Resultado
1
string(0) ""
Valora esta pregunta


0