Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php api hit的get请求中传递数据?_Php_Json_Postman - Fatal编程技术网

如何在php api hit的get请求中传递数据?

如何在php api hit的get请求中传递数据?,php,json,postman,Php,Json,Postman,我正在使用以下URL通过“GET”请求传递邮递员正文部分中的数据: "". 我正在传递的正文中的原始数据是: { "query": { "tags_include" : "92" } } 这将返回包含标记id“92”的所有学生,而不包含此原始主体数据。链接“”将返回数据库中存在的所有学生。 现在我的问题是,我试图在我的代码中传递这个body部分,如下所示: $tag_args = array( "query" => array( "tags_

我正在使用以下URL通过“GET”请求传递邮递员正文部分中的数据: "". 我正在传递的正文中的原始数据是:

 {
 "query": {
    "tags_include" : "92"
 }
}
这将返回包含标记id“92”的所有学生,而不包含此原始主体数据。链接“”将返回数据库中存在的所有学生。 现在我的问题是,我试图在我的代码中传递这个body部分,如下所示:

$tag_args = array(
        "query" => array(
        "tags_include"=>$tag_id
        )
    );
$all_tag_students = $gr->get_tag_contact($tag_args);
get_tag_contact是一个函数,它用主体点击URL“”

 {
 "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”的学生?我在这里发现了错误:

function get_tag_contact($tag_args){
    $emails = array();
    $args = $this->args;
    $args['method'] = 'GET';
    $args['body'] = $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;
    }
}
我正在对$tag_args进行编码

$args['body'] = $tag_args;

我只需要从这行代码中删除json_encode,它就可以正常工作。

GET请求不支持在正文中传递数据。如果要在GET请求上传递数据,请使用查询字符串。