2017-08-21 30 views
0

任何人都可以幫助我重寫下面的請求curl或類似的PHP 5.6中可用?我是PHP中的新的HTTP請求,我無法使用HttpRequest類,因爲它無法在服務器上找到。其他建議也歡迎。也許已經有一個圖書館?重寫Vuforia的HTTP請求

$path = "content/images/calendarmotiv/"; 
$fail = true; 


       $tmp = $_FILES['imagetarget']['tmp_name']; 
       $name = basename($_FILES['imagetarget']['name']); 
       if(move_uploaded_file($tmp, $path.$name)) 
       { 

        // http request body 
        $now = new DateTime('NOW'); 
        $body = json_encode(array(
         "name" => $name, 
         "width" => 1024.0, 
         "image_url" => base64_encode($path.$name), 
         "active_flag" => 1, 
         "application_metadata_url" => base64_encode($_POST["metadata"])) 
         ); 

        $http_verb = "POST"; 
        $content_md5 = md5($body); 
        $content_type = "application/json"; 
        $date = str_replace("+0000", "GMT", $now->format(DateTime::RFC1123)); 
        $request_path = "<a href='https://vws.vuforia.com/targets'> https://vws.vuforia.com/targets</a>"; 

        // auth string for header 
        $string_to_sign = $http_verb . "\n" . $content_md5 . "\n" . $content_type . "\n" . $date . "\n" . $request_path; 
        $secret_key = "mykey"; 
        $signature = hash_hmac("sha1", $string_to_sign, $secret_key); 
        $authstring = "VWS " . $secret_key . ":" . $signature; 

        // the request 
        $request = new HttpRequest($request_path, HttpRequest::METH_POST); 
        $request->setContentType($content_type); 
        $request->setBody($body); 
        $request->addHeaders(array(
         "Date" => $date, 
         "Authorization" => $authstring)); 

        $request->send(); 

        echo $request->getRequestMessage(); 
        echo $request->getResponseMessage(); 
       } 
+0

假設與捲曲建我認爲HTTP擴展應正常工作。跳到我身上的是'$ request_path'值是HTML標記。 – ficuscr

+0

是的,你說得對,'$ request_path'可能不應該是HTML標記。我剛剛從[link](https://developer.vuforia.com/forum/general-discussion/help-me-use-vws-api-php)複製了代碼,因爲它正是我需要的。但我無法得到這個運行。 –

+0

我發現了一個[庫](https://github.com/jacobtabak/curl-vuforia-client/blob/master/VuforiaClient.php),我可以用它來處理這個案例,但是我唯一的迴應是Vuforia **「result_code」:「BadImage」**和一個「transaction_id」,無論我上傳的圖片和目標是不是創建的。我不知道如何在沒有更多信息的情況下進行調試。任何人都看到了嗎? –

回答