卷曲返回0但不起作用

时间:2015-06-09 19:06:36

标签: php curl

我试图在curl中调用url来启动备份,这在我的浏览器中运行良好。卷曲返回0,因此似乎没有错误,但是它没有进行备份。

这是我的代码:

public function runBackup(){

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, 'http://localhost/bnc_update/kybackup/backup-in-background');
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Requested-With: XMLHTTPRequest','User-Agent: KaliMessenger'));

    curl_exec($ch);

    if( ! $result = curl_exec($ch)) 
    { 
        trigger_error(curl_error($ch)); 
        echo '<pre>';
        print_r(curl_getinfo($ch));
        echo '</pre>';
        echo 'Erreur Curl : ' . curl_errno($ch) . '<br/>';

    }  
    echo 'Result: <br/>';
    var_dump($result);

    curl_close($ch);
    exit();
}

哪个输出:

Array
(
[url] => http://localhost/bnc_update/kybackup/backup-in-background
[content_type] => text/html; charset=UTF-8
[http_code] => 301
[header_size] => 656
[request_size] => 149
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.162641
[namelookup_time] => 6.9E-5
[connect_time] => 0.000186
[pretransfer_time] => 0.000214
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.162623
[redirect_time] => 0
[redirect_url] => http://localhost/bnc_update/sign-in?back-uri=kybackup%252Fbackup-in-background
[primary_ip] => ::1
[certinfo] => Array
    (
    )

[primary_port] => 80
[local_ip] => ::1
[local_port] => 56883
)

Erreur Curl : 0
Result:
string(0) ""

我看到有一个redirect_url,可能是问题吗?我已经登录了浏览器,是否需要再次执行登录请求?

0 个答案:

没有答案