从开发服务器运行时,PHP中的CURL不连接

从开发服务器运行时,PHP中的CURL不连接,php,html,curl,wistia,Php,Html,Curl,Wistia,我用PHP将视频上传到Witia。在我的本地服务器上一切正常。但是在dev服务器中,视频没有上传。使用var_dump(curl_getinfo($ch)),我可以看到内容类型不同于本地到开发服务器。我很困惑,谁能帮我解决这个问题 这是我的代码: public function video_upload($filePath) { $data = array( 'api_password' => '0XXXXXXXXXXXXXXXXXXXXXXXX

我用PHP将视频上传到Witia。在我的本地服务器上一切正常。但是在dev服务器中,视频没有上传。使用var_dump(curl_getinfo($ch)),我可以看到内容类型不同于本地到开发服务器。我很困惑,谁能帮我解决这个问题

这是我的代码:

public function video_upload($filePath)
{         
    $data = array(
        'api_password'  => '0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5',
        'file'          => '@'.$filePath,
    );

    $url = 'https://upload.wistia.com';    
    $ch  = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL            => $url,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_HEADER         => false,
        CURLOPT_RETURNTRANSFER => true,
    ));
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $response = curl_exec($ch);

    var_dump(curl_getinfo($ch));
    var_dump(curl_errno($ch));
    curl_close($ch);

    return $response;
}
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(30) "application/json;charset=utf-8"**
    ["http_code"]=> int(200)
    ["header_size"]=> int(688)
    ["request_size"]=> int(189)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(17.850026)
    ["namelookup_time"]=> float(0.252903)
    ["connect_time"]=> float(0.253271)
    ["pretransfer_time"]=> float(1.903306)
    ["size_upload"]=> float(279250)
    ["size_download"]=> float(417)
    ["speed_download"]=> float(23)
    ["speed_upload"]=> float(15644)
    ["download_content_length"]=> float(417)
    ["upload_content_length"]=> float(279250)
    ["starttransfer_time"]=> float(2.173591)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(13) "162.209.95.19"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(13) "192.168.1.157"
    ["local_port"]=> int(54999)
    ["request_header"]=> string(189) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 279250 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------370a5719d6336ecc "
} int(0)
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(23) "text/html;charset=utf-8"**
    ["http_code"]=> int(500)
    ["header_size"]=> int(718)
    ["request_size"]=> int(186)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(0.437061)
    ["namelookup_time"]=> float(0.004766)
    ["connect_time"]=> float(0.023656)
    ["pretransfer_time"]=> float(0.194844)
    ["size_upload"]=> float(319)
    ["size_download"]=> float(30)
    ["speed_download"]=> float(68)
    ["speed_upload"]=> float(729)
    ["download_content_length"]=> float(30)
    ["upload_content_length"]=> float(319)
    ["starttransfer_time"]=> float(0.216544)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(15) "162.242.168.223"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(14) "224.178.240.48"
    ["local_port"]=> int(55164)
    ["request_header"]=> string(186) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 319 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------d45c07c28860 "
} int(0) 
在我的本地服务器中收到的响应:

public function video_upload($filePath)
{         
    $data = array(
        'api_password'  => '0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5',
        'file'          => '@'.$filePath,
    );

    $url = 'https://upload.wistia.com';    
    $ch  = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL            => $url,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_HEADER         => false,
        CURLOPT_RETURNTRANSFER => true,
    ));
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $response = curl_exec($ch);

    var_dump(curl_getinfo($ch));
    var_dump(curl_errno($ch));
    curl_close($ch);

    return $response;
}
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(30) "application/json;charset=utf-8"**
    ["http_code"]=> int(200)
    ["header_size"]=> int(688)
    ["request_size"]=> int(189)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(17.850026)
    ["namelookup_time"]=> float(0.252903)
    ["connect_time"]=> float(0.253271)
    ["pretransfer_time"]=> float(1.903306)
    ["size_upload"]=> float(279250)
    ["size_download"]=> float(417)
    ["speed_download"]=> float(23)
    ["speed_upload"]=> float(15644)
    ["download_content_length"]=> float(417)
    ["upload_content_length"]=> float(279250)
    ["starttransfer_time"]=> float(2.173591)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(13) "162.209.95.19"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(13) "192.168.1.157"
    ["local_port"]=> int(54999)
    ["request_header"]=> string(189) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 279250 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------370a5719d6336ecc "
} int(0)
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(23) "text/html;charset=utf-8"**
    ["http_code"]=> int(500)
    ["header_size"]=> int(718)
    ["request_size"]=> int(186)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(0.437061)
    ["namelookup_time"]=> float(0.004766)
    ["connect_time"]=> float(0.023656)
    ["pretransfer_time"]=> float(0.194844)
    ["size_upload"]=> float(319)
    ["size_download"]=> float(30)
    ["speed_download"]=> float(68)
    ["speed_upload"]=> float(729)
    ["download_content_length"]=> float(30)
    ["upload_content_length"]=> float(319)
    ["starttransfer_time"]=> float(0.216544)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(15) "162.242.168.223"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(14) "224.178.240.48"
    ["local_port"]=> int(55164)
    ["request_header"]=> string(186) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 319 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------d45c07c28860 "
} int(0) 
在我的开发服务器中收到的响应:

public function video_upload($filePath)
{         
    $data = array(
        'api_password'  => '0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5',
        'file'          => '@'.$filePath,
    );

    $url = 'https://upload.wistia.com';    
    $ch  = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL            => $url,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_HEADER         => false,
        CURLOPT_RETURNTRANSFER => true,
    ));
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $response = curl_exec($ch);

    var_dump(curl_getinfo($ch));
    var_dump(curl_errno($ch));
    curl_close($ch);

    return $response;
}
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(30) "application/json;charset=utf-8"**
    ["http_code"]=> int(200)
    ["header_size"]=> int(688)
    ["request_size"]=> int(189)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(17.850026)
    ["namelookup_time"]=> float(0.252903)
    ["connect_time"]=> float(0.253271)
    ["pretransfer_time"]=> float(1.903306)
    ["size_upload"]=> float(279250)
    ["size_download"]=> float(417)
    ["speed_download"]=> float(23)
    ["speed_upload"]=> float(15644)
    ["download_content_length"]=> float(417)
    ["upload_content_length"]=> float(279250)
    ["starttransfer_time"]=> float(2.173591)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(13) "162.209.95.19"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(13) "192.168.1.157"
    ["local_port"]=> int(54999)
    ["request_header"]=> string(189) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 279250 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------370a5719d6336ecc "
} int(0)
array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(23) "text/html;charset=utf-8"**
    ["http_code"]=> int(500)
    ["header_size"]=> int(718)
    ["request_size"]=> int(186)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(0.437061)
    ["namelookup_time"]=> float(0.004766)
    ["connect_time"]=> float(0.023656)
    ["pretransfer_time"]=> float(0.194844)
    ["size_upload"]=> float(319)
    ["size_download"]=> float(30)
    ["speed_download"]=> float(68)
    ["speed_upload"]=> float(729)
    ["download_content_length"]=> float(30)
    ["upload_content_length"]=> float(319)
    ["starttransfer_time"]=> float(0.216544)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(15) "162.242.168.223"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(14) "224.178.240.48"
    ["local_port"]=> int(55164)
    ["request_header"]=> string(186) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 319 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------d45c07c28860 "
} int(0) 

很难说它为什么不工作,但是您从服务器得到的响应包括一个
500
http状态代码,这表明服务器有问题

您的终端可能有问题,但是如果没有来自服务器的更多信息,就很难判断出问题出在哪里。通常,来自服务器的
500
响应表示服务器(wistia)错误,而不是客户端(您)错误


您可能想将信息发送给Witia,以获取更多详细信息。

我打赌您的发帖请求完全不同, 喜欢

然后仔细研究post请求,两台服务器发送的请求之间有什么区别?我敢打赌一定有什么。。除非你被排除在IP禁令之外


编辑:一个常见的问题,在某些安装上,curl有一个默认的useragent,而在某些安装上,curl没有。(就像在debian 6中一样,它类似于“curl/7.21.3(x86_64-unknown-linux-gnu)libcurl/7.21.3 OpenSSL/1.0.0c zlib/1.2.5”,而在debian 8中,没有默认字符串..或者是另一种方式?),许多网站会阻止不包含用户代理的请求。为了确保有一个useragent,可以使用curl_setopt($ch,CURLOPT_useragent,'curl php')

在第二次响应中,服务器出现500错误。这就是为什么它不是json