cURL对PHP脚本没有任何响应


cURL doesn't give any response on PHP script

我对PHP很陌生,所以任何帮助都会非常感激。

这是运行在WAMP服务器与cURL启用,应该上传跟踪订单,我试图处理。但是当我运行这个脚本时,我没有得到响应,所以我假设它在某个地方坏了,但是我没有得到任何错误,所以我不确定实际发生了什么。

这个问题似乎是原因,但无论是我创建$ datatpost数组的方式还是与我的代码的实际cURL部分,我认为。

if($_REQUEST)
{
    $supplier = $_REQUEST["supplier_ID"];
    $token = $_REQUEST["token"];
    $filePath = $_REQUEST["filePath"];
    $fileName = $_REQUEST["fileName"];
}
$itemID = array();
$array = file($filePath.$fileName);
foreach($array as $value)
{
    $temp = explode(",",$value);
    $itemID[] = array( "carrier" => $temp[1], "ci_lineitem_id" => $temp[0], "tracking" => $temp[2]);
}
$datatopost = array (
"supplier_id" => $supplier,
"token" => $token,
"tracking_info" =>json_encode($itemID)
);
$ch = curl_init ("https://scm.commerceinterface.com/api/v2/tracking_notification");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
if( $response ) 
{
    $response_json = json_decode( $response );
    if( $response_json['success'] == true ) 
    {
        file_put_contents($filePath."Success.txt", $response);
    } 
    else 
    {
        file_put_contents($filePath."Failed.txt", $response);
    }
}
file_put_contents($filePath."Success.txt", $responce);
file_put_contents($filePath."Failed.txt", $responce);

我认为变量$响应在file_put_contents()方法是未知的。尝试使用$response.

你正在尝试获得一个SSL安全的网站,所以看看CURLOPT_SSL_*选项:http://php.net/manual/en/function.curl-setopt.php。

有关详细信息,您应该检查cURL结果(如已经提到的)。