Php 为Vuforia重写HTTP请求

Php 为Vuforia重写HTTP请求,php,http,curl,httprequest,vuforia,Php,Http,Curl,Httprequest,Vuforia,有人能帮我用curl或PHP5.6中提供的任何类似的语言重写下面的请求吗?我是PHP中http请求的新手,无法使用HttpRequest类,因为在服务器上找不到它。我们也欢迎其他建议。也许已经有图书馆了 $path = "content/images/calendarmotiv/"; $fail = true; $tmp = $_FILES['imagetarget']['tmp_name']; $name = basena

有人能帮我用curl或PHP5.6中提供的任何类似的语言重写下面的请求吗?我是PHP中http请求的新手,无法使用HttpRequest类,因为在服务器上找不到它。我们也欢迎其他建议。也许已经有图书馆了

 $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();
                }
$path=“content/images/calendarmotiv/”;
$fail=true;
$tmp=$\u文件['imagetarget']['tmp\u名称'];
$name=basename($_文件['imagetarget']['name']);
if(移动上传的文件($tmp,$path.$name))
{
//http请求体
$now=新日期时间(“now”);
$body=json_编码(数组(
“name”=>$name,
“宽度”=>1024.0,
“image_url”=>base64_编码($path.$name),
“活动_标志”=>1,
“应用程序\u元数据\u url”=>base64\u编码($\u POST[“元数据”]))
);
$http_verb=“POST”;
$content\u md5=md5($body);
$content\u type=“应用程序/json”;
$date=str_replace(“+0000”,“GMT”,$now->format(DateTime::RFC1123));
$request_path=“”;
//标题的身份验证字符串
$string\u to\u sign=$http\u verb.\n.$content\u md5.\n.$content\u type.\n.$date.\n.$request\u path;
$secret\u key=“mykey”;
$signature=hash_hmac(“sha1”,$string_to_sign,$secret_key);
$authstring=“VWS”。$secret\u key.:”$signature;
//请求
$request=newhttprequest($request\u路径,HttpRequest::METH\u POST);
$request->setContentType($content\u type);
$request->setBody($body);
$request->addHeaders(数组)(
“日期”=>$Date,
“授权”=>$authstring));
$request->send();
echo$request->getRequestMessage();
echo$request->getResponseMessage();
}

我在PHP中创建了一个Vuforia客户端类,用于Vuforia目标数据库的基本操作:


假设使用cURL构建,我认为HTTP扩展应该可以正常工作。我突然想到的是
$request\u path
值是HTML标记。是的,你是对的,
$request\u path
可能不应该是HTML标记。我只是从中复制了代码,因为它正是我所需要的。但我无法运行此程序。我找到了一个可用于此案例的程序,但Vuforia对我的唯一回应是“结果代码”:“坏图像”和“事务id”,无论我上载了哪个图像,并且没有创建目标。如果没有进一步的信息,我不知道如何调试它。有人也看到了吗?也许用新的库显示代码?听起来好像你做得更进一步了,至少是连接了,没有得到验证错误。图像是如何上传的?作为base64编码字符串或多部分/表单数据post?我看到他们有一个PHP SDK和文档。我认为您应该能够遵循一个工作代码示例。