【发布时间】:2020-01-12 14:43:59
【问题描述】:
我正在尝试使用 cURL 对博客文章发表评论,但最终出现“rest_invalid_param”错误。
我尝试在邮递员的 cURL 中运行相同的 URL,它运行良好。我不知道我哪里出错了。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/aapta-blog/wp-json/wp/v2/comments");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = array(
'author_email' => urlencode($user_email),
'author_name' => urlencode($user_name),
'content' => urlencode($content),
'post' => urlencode($post_id)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
die();
我什至尝试过 json_encode($data),但仍然出现错误。 我在邮递员中传递的是http://example.com/aapta-blog/wp-json/wp/v2/comments?author_email=novusflos.web@gmail.com&author_name=Danu&content=Test from postman2&post=38
错误:
{
code: "rest_invalid_param",
message: "Invalid parameter(s): post",
data: {
status: 400,
params: {
post: "post is not of type integer."
}
}
}
【问题讨论】:
标签: php wordpress codeigniter curl