1

Using Chrome to inspect the url: http://www.wizards.com/Magic/PlaneswalkerPoints/76954206# I am able to see the url where the JSON data is grabbed from:

Request URL:http://www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/76954206

Running my code:

$user_agent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36'; 
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 5s
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($json)));
curl_setopt($ch, CURLOPT_POST, 1);

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// further processing ....
if ($server_output == "OK") { 
  print_r($ch);
} else {
  echo "Boo";
}

Leaves me with a blank page. It's not returning JSON, only the redirect error page.

Is there a certain call I am missing to grab the JSON data?

1 Answer 1

2

Try this:

<?php

$url = 'http://www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/76954206';

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS, '');
$result = curl_exec($ch);
curl_close($ch);

echo $result;

Output:

{"Result":true,"SessionExpired":false,"Data":[{"Key":"LifetimePoints","Value":6016,"ReplaceElement...

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Idk why I was trying to over complicate the whole thing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.