$attributes = $shop->products->attributes($namespaces['xlink']); $productsUrl = $attributes->href; $header = array(); $header[] = createSprdAuthHeader("POST", $productsUrl); $header[] = "Content-Type: application/xml"; $ch = curl_init($productsUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POSTFIELDS, $product->asXML()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); $result = curl_exec($ch); // Close the handle curl_close($ch); $productUrl = parseHttpHeaders($result, "Location"); $ch = curl_init($productUrl); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $result = curl_exec($ch); // Close the handle curl_close($ch); $product = new SimpleXMLElement($result); $resource = $product->resources->resource[0]; $attributes = $resource->attributes($namespaces['xlink']); echo '<html><body>'; echo 'Product available at: <a href="' . $productUrl . '">' . $productUrl . '</a></br>'; echo 'Product image is available at: <a href="' . $attributes->href . '">' . $attributes->href . '</a></br>'; echo '<img src="' . $attributes->href . '?width=1000"/>'; echo '</body></html>';
// Open the Curl session $session = curl_init(secureUrl('POST', $url)); curl_setopt($session, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($session, CURLOPT_POST, true); curl_setopt($session, CURLOPT_POSTFIELDS, @file_get_contents('php://input')); curl_setopt($session, CURLOPT_HTTPHEADER, getRelevantRequestHeaders()); curl_setopt($session, CURLOPT_HEADER, true); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Make the call $response = curl_exec($session); // The web service returns XML. Set the Content-Type appropriately header("Content-Type: application/xml", true); header("Location: " . parseHttpHeaders($response, "Location"), true); header(getStatusMessage("".curl_getinfo($session, CURLINFO_HTTP_CODE))); curl_close($session); break; case 'GET': //echo $_GET['url'] . "#"; $url = encodeUrl($_GET['url']); //echo $url; if (isset($_GET['secure']) && $_GET['secure'] == "true") $url = secureUrl("GET", $url); // Open the Curl session $session = curl_init($url); // fix this security leak
$header = array(); $header[] = createSprdAuthHeader("POST", $url); $header[] = "Content-Type: application/xml"; $xml = getFileData("design.xml"); // Initialize handle and set options $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); $result = curl_exec($ch); // Close the handle curl_close($ch); $dataUrl = parseHttpHeaders($result, "Location"); echo "Design URL: " . $dataUrl . "\n"; // 2. Fetch design data to retrieve upload url $ch = curl_init($dataUrl); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $result = curl_exec($ch); // Close the handle curl_close($ch); $start = strpos($result, "resource xlink:href=\"") + 21; $end = strpos($result, "\"", $start); $imageUrl = substr($result, $start, $end - $start); echo "Image URL: " . $imageUrl . "\n"; // 3. Upload design data via image API $imageData = getFileData("design.png");