如何解决WC API:返回了无效的JSON
我在这里做错了什么?自从我杀死Google和stackoverflow以来已经有两天了。。。我不知道:(((
我已经在线检查了返回的正文json(由于太长而未在此处粘贴),并且是有效的json ...问题出在哪里?!
未安装缓存插件,邮递员中的相同请求返回OK结果,直接在浏览器中测试请求URL返回OK结果,一切都很好,除非在我的项目中使用im ...
Automattic \ WooCommerce \ HttpClient \ HttpClientException对象 ( [request:Automattic \ WooCommerce \ HttpClient \ HttpClientException:private] => Automattic \ WooCommerce \ HttpClient \ Request对象 ( [url:Automattic \ WooCommerce \ HttpClient \ Request:private] => https://www.viatainrawz.ro/wp-json/wc/v3/products [方法:Automattic \ WooCommerce \ HttpClient \ Request:private] => GET [参数:Automattic \ WooCommerce \ HttpClient \ Request:private] =>数组 ( )
[headers:Automattic\WooCommerce\HttpClient\Request:private] => Array
(
[Accept] => application/json
[Content-Type] => application/json
[User-Agent] => WooCommerce API Client-PHP/1.0.2
)
[body:Automattic\WooCommerce\HttpClient\Request:private] =>
)
[response:Automattic\WooCommerce\HttpClient\HttpClientException:private] => Automattic\WooCommerce\HttpClient\Response Object
(
[code:Automattic\WooCommerce\HttpClient\Response:private] => 200
[headers:Automattic\WooCommerce\HttpClient\Response:private] => Array
(
[date] => Mon,31 Aug 2020 09:26:42 GMT
[content-type] => application/json; charset=UTF-8
[vary] => Accept-Encoding
[x-robots-tag] => noindex
[x-content-type-options] => nosniff
[access-control-expose-headers] => X-WP-Total,X-WP-TotalPages,Link
[access-control-allow-headers] => Authorization,X-WP-Nonce,Content-disposition,Content-MD5,Content-Type
[expires] => Wed,11 Jan 1984 05:00:00 GMT
[cache-control] => no-cache,must-revalidate,max-age=0
[x-wp-total] => 49
[x-wp-totalpages] => 5
[link] => <https://viatainrawz.ro/wp-json/wc/v3/products?page=2>; rel="next"
[allow] => GET,POST
[server] => ClausWeb-Nginx
[cluster-host] => server46.romania-webhosting.com
)
)
[message:protected] => Invalid JSON returned
[string:Exception:private] =>
[code:protected] => 200
[file:protected] => /home/vreaumob/worker.vreaumobila.ro/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.PHP
[line:protected] => 303
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /home/vreaumob/worker.vreaumobila.ro/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.PHP
[line] => 346
[function] => lookForErrors
[class] => Automattic\WooCommerce\HttpClient\HttpClient
[type] => ->
[args] => Array
(
[0] =>
)
)
[1] => Array
(
[file] => /home/vreaumob/worker.vreaumobila.ro/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.PHP
[line] => 382
[function] => processResponse
[class] => Automattic\WooCommerce\HttpClient\HttpClient
[type] => ->
[args] => Array
(
)
)
[2] => Array
(
[file] => /home/vreaumob/worker.vreaumobila.ro/vendor/automattic/woocommerce/src/WooCommerce/Client.PHP
[line] => 82
[function] => request
[class] => Automattic\WooCommerce\HttpClient\HttpClient
[type] => ->
[args] => Array
(
[0] => products
[1] => GET
[2] => Array
(
)
[3] => Array
(
)
)
)
[3] => Array
(
[file] => /home/vreaumob/worker.vreaumobila.ro/apitest.PHP
[line] => 24
[function] => get
[class] => Automattic\WooCommerce\Client
[type] => ->
[args] => Array
(
[0] => products
)
)
)
[prevIoUs:Exception:private] =>
) 返回了无效的JSON
解决方法
我使用的代码:
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
try {
$woocommerce = new Client( 'https://www.viatainrawz.ro','XX',[
'verify_ssl' => false,'version' => 'wc/v3'
]
);
print_r($woocommerce->get('products'));
} catch (HttpClientException $e) {
\print_r($e);
\print_r($e->getMessage() . PHP_EOL);
\print_r('Code: ' . $e->getResponse()->getCode() . PHP_EOL);
\print_r('Body: ' . $e->getResponse()->getBody() . PHP_EOL);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。