многомерный массив в curl_opts, curl_exec возвращает false

0

У меня проблема с json-ответом в Symfony2.

Мой массив jobList:

    array(4) {
  ["id"]=>
  int(1)
  ["jsonrpc"]=>
  string(3) "2.0"
  ["method"]=>
  string(11) "getJobsList"
  ["params"]=>
  array(3) {
    [0]=>
    array(8) {
      ["id"]=>
      int(1)
      ["url"]=>
      string(5) "jhbjb"
      ["active"]=>
      NULL
      ["ping_time"]=>
      NULL
      ["start_time"]=>
      NULL
      ["stop_time"]=>
      NULL
      ["search_phrase"]=>
      string(5) "jhbjh"
      ["phrase_type"]=>
      NULL
    }
    [1]=>
    array(8) {
      ["id"]=>
      int(5)
      ["url"]=>
      string(6) "kjnkjn"
      ["active"]=>
      NULL
      ["ping_time"]=>
      NULL
      ["start_time"]=>
      NULL
      ["stop_time"]=>
      NULL
      ["search_phrase"]=>
      string(5) "kjnkn"
      ["phrase_type"]=>
      NULL
    }
    [2]=>
    array(8) {
      ["id"]=>
      int(9)
      ["url"]=>
      string(12) "http://bhbjb"
      ["active"]=>
      NULL
      ["ping_time"]=>
      NULL
      ["start_time"]=>
      NULL
      ["stop_time"]=>
      NULL
      ["search_phrase"]=>
      string(6) "jbjhbh"
      ["phrase_type"]=>
      NULL
    }
  }
}

Отправить функцию:

private function sendJobList($jobList, $agentUrl)
    {



        if (!empty($jobList)) {
            if (!$agentUrl) {
               $url = $agentUrl;
            }
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data'));
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            if($jobList)
            {
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($jobList));
            }

            $output = curl_exec($ch);
            var_dump($output);die();
            curl_close($ch);

            return new Response(json_encode($output, true));
        } else {
            return new Response("Lista jest pusta");
        }
    }

Я не знаю, почему curl_exec возвращает false. Я везде искал ответ, но ничего не помогало. Буду благодарен за любую помощь.

Теги:
curl

1 ответ

0

вы должны изменить условие if, если $ urlagent

Я думаю, что это должно быть wrotten таким образом:

if($agenturl){
    $url= $agenturl;
}

или

if(isset($agenturl)){
        $url= $agenturl;
    }

Ещё вопросы

Сообщество Overcoder
Наверх
Меню