dongmangzong8006 2015-11-11 14:20
浏览 844

执行cURL POST时出现500错误

I'm trying to construct a $cpe array to match the format of an expected array - so I make a cURL POST into a database.


1: Construct $cpe array

    $cpe = [];

    $cpe['cpe_mac'] = $cpe_mac;
    $cpe['bandwidth_max_up'] = (int)$inputs['max_up'];
    $cpe['bandwidth_max_down'] = (int)$inputs['max_down'];
    $cpe['filter_icmp_inbound'] = true ;
    $cpe['dmz_enabled'] = false ;
    $cpe['dmz_host'] = 'http:\/\/ddd.com' ;
    $cpe['vlan_id'] = 2 ;
    $cpe['dns'] = ['8.8.8.8','4.2.2.1'] ;
    $cpe['xdns_mode'] = 0 ;
    $cpe['cfprofileid'] = 11111 ;
    $cpe['stub_response'] = 0 ;
    $cpe['acl_mode'] = 1 ;
    $cpe['portal_url'] = 'http:\/\/portal.com' ;
    $cpe['fullbandwidth_max_up'] = 1000000 ;
    $cpe['fullbandwidth_max_down'] = 2000000 ;
    $cpe['fullbandwidth_guaranty_up'] = 300000 ;
    $cpe['fullbandwidth_guaranty_down'] = 400000 ;
    $cpe['account_id'] = (int)$inputs['account_id'];
    $cpe['location_id'] = 3333 ;
    $cpe['network_count'] = 3 ;
    $cpe['group_name'] = 'test_group' ;
    $cpe['vse_id'] = 20 ;
    $cpe['firewall_enabled'] = false ;


    dd($cpe);

2: Data of $cpe array

array:23 [▼
  "cpe_mac" => "803911817640"
  "bandwidth_max_up" => 30000
  "bandwidth_max_down" => 50000
  "filter_icmp_inbound" => true
  "dmz_enabled" => false
  "dmz_host" => "http:\/\/ddd.com"
  "vlan_id" => 2
  "dns" => array:2 [▼
    0 => "8.8.8.8"
    1 => "4.2.2.1"
  ]
  "xdns_mode" => 0
  "cfprofileid" => 11111
  "stub_response" => 0
  "acl_mode" => 1
  "portal_url" => "http:\/\/portal.com"
  "fullbandwidth_max_up" => 1000000
  "fullbandwidth_max_down" => 2000000
  "fullbandwidth_guaranty_up" => 300000
  "fullbandwidth_guaranty_down" => 400000
  "account_id" => 1000
  "location_id" => 3333
  "network_count" => 3
  "group_name" => "test_group"
  "vse_id" => 20
  "firewall_enabled" => false
]

3: Expected Data (Sample)

My goal is match this array in order to make a POST

{
"cpe_mac":"a0a1a2a3a4a5",
"bandwidth_max_up":300000,
"bandwidth_max_down":500000,
"filter_icmp_inbound":true,
"dmz_enabled":false,
"dmz_host":"http:\/\/ddd.com",
"vlan_id":2,
"dns":[
"8.8.8.8",
"4.2.2.1"
],
"xdns_mode":0,
"cfprofileid":11111,
"stub_response":"",
"acl_mode":1,
"portal_url":"http:\/\/portal.com",
"fullbandwidth_max_up":1000000,
"fullbandwidth_max_down":2000000,
"fullbandwidth_guaranty_up":300000,
"fullbandwidth_guaranty_down":400000,
"account_id":1234,
"location_id":3333,
"network_count":3,
"group_name":"test_group",
"vse_id":20,
"firewall_enabled":false
}

4: Error

Then, I json_encode that cpe array and make a curl post to a URL.

I keep getting

array:3 [▼
  "status" => 500
  "error_code" => 1005
  "message" => """
    error exception retrieving data for [select * from spc_vse_vcpe_iu (  json_inp := '{"cpe_mac":"204492519985","bandwidth_max_up":30000,"bandwidth_max_down":50000,"filter_icmp_inbound":true,"dmz_enabled":false,"dmz_host":"http:\\\/\\\/ddd.com","vlan_id":2,"dns":["8.8.8.8","4.2.2.1"],"xdns_mode":0,"cfprofileid":11111,"stub_response":0,"acl_mode":1,"portal_url":"http:\\\/\\\/portal.com","fullbandwidth_max_up":1000000,"fullbandwidth_max_down":2000000,"fullbandwidth_guaranty_up":300000,"fullbandwidth_guaranty_down":400000,"account_id":1000,"location_id":3333,"network_count":3,"group_name":"test_group","vse_id":20,"firewall_enabled":false}'); ]. error=[42883 ERROR:  function spc_vse_vcpe_iu(json_inp := unknown) does not exist

    LINE 1: select * from spc_vse_vcpe_iu (  json_inp := '{"cpe_mac":"20...

                          ^

    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

    ]

    """
]

5: Controller (Store Function)

Here is everything I have

public function store() {

        $inputs = Input::all();
        unset($inputs['_token']);

        $cpe_mac = $inputs['mac1'].$inputs['mac2'].$inputs['mac3'].$inputs['mac4'].$inputs['mac5'].$inputs['mac6'];

        $cpe = [];

        $cpe['cpe_mac'] = $cpe_mac;
        $cpe['bandwidth_max_up'] = (int)$inputs['max_up'];
        $cpe['bandwidth_max_down'] = (int)$inputs['max_down'];
        $cpe['filter_icmp_inbound'] = true ;
        $cpe['dmz_enabled'] = false ;
        $cpe['dmz_host'] = 'http:\/\/ddd.com' ;
        $cpe['vlan_id'] = 2 ;
        $cpe['dns'] = ['8.8.8.8','4.2.2.1'] ;
        $cpe['xdns_mode'] = 0 ;
        $cpe['cfprofileid'] = 11111 ;
        $cpe['stub_response'] = 0 ;
        $cpe['acl_mode'] = 1 ;
        $cpe['portal_url'] = 'http:\/\/portal.com' ;
        $cpe['fullbandwidth_max_up'] = 1000000 ;
        $cpe['fullbandwidth_max_down'] = 2000000 ;
        $cpe['fullbandwidth_guaranty_up'] = 300000 ;
        $cpe['fullbandwidth_guaranty_down'] = 400000 ;
        $cpe['account_id'] = (int)$inputs['account_id'];
        $cpe['location_id'] = 3333 ;
        $cpe['network_count'] = 3 ;
        $cpe['group_name'] = 'test_group' ;
        $cpe['vse_id'] = 20 ;
        $cpe['firewall_enabled'] = false ;

        $json = json_encode($cpe);

        $ch = curl_init( env('API_HOST').'vse/vcpe');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('json' => $json)));
        $result = curl_exec($ch);
        curl_close($ch);

        $result_json =  json_decode($result, true);
        dd($result_json);

        $id = Auth::user()->account_id;

        if ( $result_json['status'] == '200') {
            return Redirect::to('/account/'.$id.'#hardware') ->with('success','The CPE was created succesfully!');
        } else {

            dd($result_json);
            return Redirect::to('/account/'.$id.'#hardware') ->with('error', $result_json['message']);
        }


      return Redirect::to('/account') ->with('success','The CPE was created succesfully!');

    }

I'm a little stuck now. I couldn't spot what I did wrong. Any help on this will mean a lot to me.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用