首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >POST API问题-不起作用

POST API问题-不起作用
EN

Stack Overflow用户
提问于 2022-09-04 15:33:35
回答 1查看 18关注 0票数 0

下午好,

我在api POST请求方面遇到了麻烦--它根本不会出现在API日志上--我有各种get请求运行良好,但这个请求没有--我不知道我做错了什么。

代码语言:javascript
复制
public function broadband_plan(){
        $common = array();
        $common['main_menu'] = 'Broadband plan';

        $cli_or_postcode = isset($_GET["cli_or_postcode"]) ? $_GET["cli_or_postcode"] : "";
        $district_id = isset($_GET["district_id"]) ? $_GET["district_id"] : "";
        $sub_premises = isset($_GET["sub_premises"]) ? $_GET["sub_premises"] : "";
        $premises_name = isset($_GET["premises_name"]) ? $_GET["premises_name"] : "";
        $thoroughfare_number = isset($_GET["thoroughfare_number"]) ? $_GET["thoroughfare_number"] : "";
        $thoroughfare_name = isset($_GET["thoroughfare_name"]) ? $_GET["thoroughfare_name"] : "";
        $locality = isset($_GET["locality"]) ? $_GET["locality"] : "";
        $postcode = isset($_GET["postcode"]) ? $_GET["postcode"] : "";
        $nad_key = isset($_GET["nad_key"]) ? $_GET["nad_key"] : "";
        $post_town = isset($_GET["post_town"]) ? $_GET["post_town"] : "";
        $county = isset($_GET["county"]) ? $_GET["county"] : "";
        $district_id = isset($_GET["district_id"]) ? $_GET["district_id"] : "";

        $request = array();
        $request['apiUsername'] = 'XXXXXXX';
        $request['apiPassword'] = 'XXXXXXX';
        $request['encryption']   = 'SHA-512';
        $request['platform']     = 'LIVE';
        $request['method']       = 'POST';
        
        $address = '{
            "sub_premises": $sub_premises,
            "premises_name": $premises_name,
            "thoroughfare_number": $thoroughfare_number,
            "thoroughfare_name": $thoroughfare_name,
            "post_town": $post_town,
            "postcode": $postcode,
            "district_id": $district_id,
            "nad_key": $nad_key
        }';
        $address = json_encode($address);

        $request['url'] = "/broadband/availability" . $address;
        
        
    
        $broadband_plan_detail = array();
        if (!empty($address)) {
            $broadband_plan_detail = $this->get_plan($request);
        }

        return view('front.broadband_plan',compact('common','broadband_plan_detail'));
    }
EN

回答 1

Stack Overflow用户

发布于 2022-09-04 15:45:19

$address after $address = json_encode($address);将是一个对象,它不能作为字符串连接在$request‘’url‘=“/宽频/可用性”中。$address;

请检查您的API并确保您遵循它们的结构,例如,如果API URL接受参数作为GET请求,您可以传递参数如下:

$request‘’url‘=“/宽频/可用性?子房地=”。$sub_premises。"&premises_name=“。$premises_name...

基于您的代码,API方法是POST,因此您可能需要将参数作为数组来准备。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73600654

复制
相关文章

相似问题

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