Skip to content

Instantly share code, notes, and snippets.

@andrzj
Last active October 2, 2017 19:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save andrzj/007ba45d40a2c0fe1fb83ea2fba90b2f to your computer and use it in GitHub Desktop.
Posting JSON and Cookie via file_get_contents
$urlC = "http://test.com/api/v1/graph/ql";
$jsonData = '{"query": "query CoralAdmin_Dashboard($from: Date!, $to: Date!) {\n assetsByActivity: assetMetrics(from: $from, to: $to, sortBy: ACTIVITY) {\n ...CoralAdmin_Metrics\n }\n}\n\nfragment CoralAdmin_Metrics on Asset {\n id\n title\n url\n created_at\n commentCount\n }\n","variables": { "from": "2017-09-18T10:01:58.350Z", "to": "2017-09-21T18:06:58.350Z" }, "operationName": "CoralAdmin_Dashboard" }';
$options = array(
'http' => array(
'method' => 'POST',
'content' => $jsonData,
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Cookie: NAME=VaLuE"
)
);
$context = stream_context_create($options);
$result = file_get_contents($urlC, false, $context );
$response = json_decode($result, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment