使用rest api更新详细信息时出错 [英] Error updating the details using rest api

查看:38
本文介绍了使用rest api更新详细信息时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码更新产品价格.但由于某种原因它显示错误.这是文档.请检查这个.

Hi i try to update a product price using the following code . But for some reason it showing error . This is documentation . Please check this .

$storeId   = storeid;
$productId = myproductid;
$myToken   = mytoken;
$dataRAW   = json_encode( array( 'price' => 80 ), JSON_FORCE_OBJECT );
$dataToPut = $dataRAW;
$dataRAW   = http_build_query($dataRAW);
$context   = [
    'http' => [
        'method' => 'PUT',
        'header' => "Authorization: apikeystring\r\n" . "Content-Length: ".sizeof($dataToPut)."\r\n" . "Content-Type: application/json\r\n",
        'content' => $dataToPut
    ] 
];

$context   = stream_context_create($context);
$url       = "https://app.ecwid.com/api/v3/".urlencode($storeId)."/products/".urlencode($productId)."?token=".$myToken; 
$dataToPut = json_encode($dataToPut);


$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host: app.ecwid.com','Content-Type: application/json;charset=utf-8','Cache-Control: no-cache'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $dataToPut);

// Make the REST call, returning the result
$response = curl_exec($curl);
echo $response;

if (!$response) {
    echo("Connection Failure: ".curl_error($curl));
    die();
}
curl_close($curl);

我在我的 localhost 中运行此代码.http://localhost/ecwid/code.php

I run this code in my localhost . http://localhost/ecwid/code.php

警告:http_build_query():参数 1 应为数组或对象.第 7 行 C:\xampp\htdocs\ecwid\code.php 中给出的值不正确

Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in C:\xampp\htdocs\ecwid\code.php on line 7

警告:sizeof():参数必须是一个数组或一个在C:\xampp\htdocs\ecwid\code.php第11行实现Countable的对象

Warning: sizeof(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\ecwid\code.php on line 11

连接失败:错误设置证书验证位置:CAfile:C:\xampp\apache\bin\curl-ca-bundle.crt CApath:none

Connection Failure: error setting certificate verify locations: CAfile: C:\xampp\apache\bin\curl-ca-bundle.crt CApath: none

推荐答案

您在 http_build_query 中传递 JSON 数据所以它发生了,http_build_query 只接受数组参数并转换为查询字符串.您可以参考以下示例.

You are passing JSON data in http_build_query so it happened, http_build_query take only array params and convert into the query string. You can take reference from the following the example.

$dataRAW   = ['price' => 80];
$dataRAW   = http_build_query($dataRAW);

这篇关于使用rest api更新详细信息时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆