1

I'm trying to retrieve the user's design after creating a session (login) but I keep getting a parsing error: XML Parsing Error: junk after document element. I tried this on my local machine and on the server side as well. on the servers side, I only get a blank page since I think the errors are set not to be displayed.

Here is my code:

$ch = curl_init("http://api.spreadshirt.$tld/api/v1/sessions");
curl_setopt($ch, CURLOPT_HEADER, true); // get the header
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, '');

$result = curl_exec($ch);

if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
return null;
}
curl_close($ch);
$headers = parseHttpHeaders($result);
$arr = explode('/', $headers[0]['Location']);
define('SESSION_ID', $arr[count($arr) - 1]);

$header = array();
$header[] = createSprdAuthHeader("GET", "http://api.spreadshirt.$tld/api/v1/users/$userId/designs");
$header[] = "Content-Type: application/xml";
$ch = curl_init("http://api.spreadshirt.$tld/api/v1/users/$userId/designs");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_ENCODING, '');
$result = curl_exec($ch);
curl_close($ch);

header('Content-Type: application/xml; charset=utf-8');
echo $result;

function createSprdAuthHeader($method, $url) {
$apiKey = SPREADSHIRT_API_KEY;
$secret = SPREADSHIRT_API_SECRET;
$session = SESSION_ID;
$time = time() * 1000;

$data = "$method $url $time";
$sig = sha1("$data $secret");

return "Authorization: SprdAuth apiKey=\"$apiKey\", data=\"$data\", sig=\"$sig\", sessionId=\"$session\"";
}
Ash23
  • 37
  • 5
  • If you don't get any errors because there aint some, then there is no problem. If you don't get any errors because you don't log errors to file and look into the logfile, then you need to start logging errors. – hakre Mar 27 '15 at 18:37
  • they use their own xml so I had to match what they used which I finally was able to do and get the results I wasted. – Ash23 Mar 28 '15 at 14:41
  • So you got errors of non objects I assume? – hakre Mar 28 '15 at 19:56

0 Answers0