首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在GUSOS6HTTP客户端中发布布尔值

无法在GUSOS6HTTP客户端中发布布尔值
EN

Stack Overflow用户
提问于 2016-09-01 17:44:57
回答 1查看 2.6K关注 0票数 0

我现在真的很沮丧,我需要更有经验的口香糖专家的帮助。

如果我想要一个来自API服务器的代码消息响应,而不是一个完整的链接响应,我将连接到一个API,它需要一个布尔值。

下面是由原始http客户端(Postman)访问的两种返回类型之间区别的示例:

启用布尔代码:

禁用布尔代码:

我遇到的问题是,当我使用get 6发出相同的请求时,我总是会得到完整的链接响应,并且永远无法在post正文中得到要应用的布尔值。看来布尔参数被压缩为“true”(这是我的猜测)。

因此,以下两个POST请求产生完全相同的结果:

代码语言:javascript
运行
复制
        // define request parameters
        $this->req_body = [
            'email' => $encrypted_email,
            'code'  => true
        ];

        // request url
        $request_url = $api_endpoint . self::RETURN_TYPE;

        // instance of Guzzle Client
        $client = $this
                    ->client();

        // abstract connection
        // XXX: this request needs no headers
        $response = $client
                        ->post($request_url, array(
                            'form_params' => $this->req_body
                        ));
        // real data
        $data = $response
                        ->getBody()
                        ->getContents();

        // send output
        $this->response = $data;

如果我尝试使用注释掉的code表单参数:

代码语言:javascript
运行
复制
        // define request parameters
        $this->req_body = [
            'email' => $encrypted_email\\,
            //'code'    => true
        ];

        // request url
        $request_url = $api_endpoint . self::RETURN_TYPE;

        // instance of Guzzle Client
        $client = $this
                    ->client();

        // abstract connection
        // XXX: this request needs no headers
        $response = $client
                        ->post($request_url, array(
                            'form_params' => $this->req_body
                        ));
        // real data
        $data = $response
                        ->getBody()
                        ->getContents();

        // send output
        $this->response = $data;

返回的API响应总是:"{"success":{"code":200,"message":"https:\/\/webservices.bvdpetroleum.com\/users\/user-password-reset\/q8VqSAbfTOkW0EMvSTfK5qSS4zr28rSwdQy3D\/uc9wtz3+RI4LH7hDkh\/ZbTfqcC"}}"

如何在Boolean 6 form_params数组中发送form_params值?任何洞察力都会非常感谢,因为我不想切换到CURL

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-01 18:39:04

只需更改form_params数组以作为json post正文发送:)

代码语言:javascript
运行
复制
$response = $client->post($request_url, array(
               'json' => $this->req_body
            ));
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39277861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档