【发布时间】:2020-05-26 12:09:08
【问题描述】:
我通过“GET”请求在邮递员的正文部分中传递数据,并使用此 URL: “http://localhost:8888/wordpress/wp-json/gh/v3/contacts”。 我传递的正文中的原始数据是:
{
"query": {
"tags_include" : "92"
}
}
这将返回包含标签 ID“92”的所有学生,而没有此原始正文数据链接“http://localhost:8888/wordpress/wp-json/gh/v3/contacts”将返回数据库中存在的所有学生。 现在我的查询是我试图在我的代码中传递这个正文部分:
$tag_args = array(
"query" => array(
"tags_include"=>$tag_id
)
);
$all_tag_students = $gr->get_tag_contact($tag_args);
get_tag_contact 是用正文点击 URL“http://localhost:8888/wordpress/wp-json/gh/v3/contacts”的函数
{
"query": {
"tags_include" : "92"
}
}
这是我为此创建的函数:
function get_tag_contact($tag_args){
$emails = array();
$args = $this->args;
$args['method'] = 'GET';
$args['body'] = json_encode($tag_args);
$response = wp_remote_get($this->apiurl.'contacts',$args);
$body = json_decode( wp_remote_retrieve_body( $response ) );
if(!empty($body)){
foreach ($body->contacts as $contact)
{
$emails[] = $contact->data->email;
}
return $emails;
}
}
但这里的问题是它返回所有学生,而不仅仅是包含 ID 的特定学生
Array
(
[query] => Array
(
[tags_include] => 92
)
)
我怎样才能找到包含 id "92" 的学生只有我在这里缺少的东西?
【问题讨论】:
-
GET 请求不支持在正文中传递数据。如果要在 GET 请求中传递数据,请使用查询字符串。