Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在localhost上,它运行正常,但联机时会发出警告Curl_setopt()希望参数1是资源,在_Javascript_Php_Curl_Localhost_Web Hosting - Fatal编程技术网

Javascript 在localhost上,它运行正常,但联机时会发出警告Curl_setopt()希望参数1是资源,在

Javascript 在localhost上,它运行正常,但联机时会发出警告Curl_setopt()希望参数1是资源,在,javascript,php,curl,localhost,web-hosting,Javascript,Php,Curl,Localhost,Web Hosting,在我的本地主机上,它运行得很好,但在我的web主机上,我得到了以下错误 PHP警告:curl_setopt()要求参数1为resource,在第15、16、18和19行的\WINDOWSxxxx.LOCAWEB.COM.BR\xxxx\xxxxx\pagamento.PHP中给出空值 我不知道这是不是语法错误 <?php include 'config.php'; //session_start(); #create the request $url =

在我的本地主机上,它运行得很好,但在我的web主机上,我得到了以下错误

PHP警告:curl_setopt()要求参数1为resource,在第15、16、18和19行的\WINDOWSxxxx.LOCAWEB.COM.BR\xxxx\xxxxx\pagamento.PHP中给出空值

我不知道这是不是语法错误

<?php

    include 'config.php';
    //session_start();
    #create the request
    $url = URL_PAGSEGURO."sessions?email=".EMAIL_PAGSEGURO."&token=".TOKEN_PAGSEGURO;

    //http://br2.php.net/manual/pt_BR/function.curl-setopt.php

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded; charset=UTF-8"));
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, true);

    $retorno = curl_exec($curl);
    curl_close($curl);

    $xml = simplexml_load_string($retorno);
    echo json_encode($xml);

我对在PHP上使用curl还不熟悉(请不要太苛刻),我发现这更方便用户,更少键入。。我希望这会有所帮助。我没有包括你所有的参数,这只是告诉你另一种方式

$curl = curl_init();

$apiURL; // This will have to be set
$data; // This will have to be set

curl_setopt_array($curl, array(
    CURLOPT_URL => $url,
    CURLOPT_POSTFIELDS => $data,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POST=>true,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_RETURNTRANSFER => true;
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
        'x-api-key: nPwrkTQyjW7DnFdvU='
    )
));

$response = json_decode(curl_exec($curl), true);
curl_close($curl);


在你发布这个问题之前,请包括你已经阅读过的搜索解决方案的其他帖子。