请求使用HTTP Outh 2身份验证和PHP curl不起作用?
我已经使用请求使用HTTP Outh 2身份验证和PHP curl不起作用?,php,authentication,curl,Php,Authentication,Curl,我已经使用PHP CURL和以下代码设置了一个http请求 <?php $para='{ "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market",
PHP CURL
和以下代码设置了一个http请求
<?php
$para='{
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe@example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"line_items": [
{
"product_id": 13,
"quantity": 2
}
]
}';
$process= curl_init('http://xxx');
$header[] = 'Content-Type: application/json';
curl_setopt($process, CURLOPT_HEADER, $header);
curl_setopt($process, CURLOPT_POST, true);
curl_setopt($process, CURLOPT_POSTFIELDS, urlencode("oauth_consumer_key=xxxxxxfa18148227334d91&
oauth_signature_method=HMAC-SHA1&
oauth_signature=xxxxx%253D&
oauth_timestamp=xxxx&
oauth_nonce=xxXbG&
oauth_version=2.0"));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS, $para);
$return = curl_exec($process);
print_r($return);
curl_close($process);
?>
有人请帮我解决这个问题吗?变量
$process
来自哪里?正如错误所说,它是null
。请发布完整的代码。错误很明显-作为调用curl_setopt()的第一个参数传递的$process
为空。与您在标题中提到的OAuth完全无关。在您的代码中,$process
是调用curl\u init()
的结果……现在开始阅读:。它说“成功时返回一个cURL句柄,错误时返回FALSE”。所以它真的应该返回一些东西。根据您的代码,它是如何变为null的是一个谜。但是,您可能至少会仔细检查代码,看看对curl_init()的调用是否成功。
{"code":"woocommerce_rest_cannot_create","message":"Sorry, you are not allowed to create resources.","data":{"status":401}}