curl request php

Solutions on MaxInterview for curl request php by the best coders in the world

showing results for - "curl request php"
Carlos
06 Nov 2018
1$data = array(
2            "userId" => "1"
3        );
4
5        $headers = array(
6            'Content-Type: application/json'
7        );
8        $url = "ip/api";
9        $curl = curl_init($url);
10        curl_setopt($curl, CURLOPT_POST, 1);
11        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
12        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
13        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
14        $response = curl_exec($curl);
15        curl_close($curl);
16        $jsonObject = json_decode($response);
17        return $jsonObject;