执行cURL POST时出现500错误

时间:2015-11-11 14:20:51

标签: php arrays laravel curl laravel-5.1

我正在尝试构建$cpe array匹配expected array的格式 - 所以我将cURL POST构建到数据库中。

1:构造$ cpe数组

    $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:$ cpe数组的数据

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:预期数据(样本)

我的目标是匹配此数组以进行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:错误

然后,我json_encode cpe数组并向网址发送一个卷曲帖。

我一直在

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\n
    LINE 1: select * from spc_vse_vcpe_iu (  json_inp := '{"cpe_mac":"20...\n
                          ^\n
    HINT:  No function matches the given name and argument types. You might need to add explicit type casts.\n
    ]\n
    """
]

5:控制器(存储功能)

这是我拥有的一切

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!');

    }

我现在有点卡住了。我无法发现我做错了什么。 对此有任何帮助对我来说意义重大。

0 个答案:

没有答案