PHP Curl返回http_code 0

时间:2017-01-19 12:34:18

标签: php curl

我有一个非常简单的卷曲帖子,从我的一个服务器到另一个只获取状态名称。 从昨天起它工作得很好,今天突然间它破了。

这是我的CURL脚本

$array = array("Task" => "getStateNames");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://domainname.com/api/c.php");
curl_setopt($ch, CURLOPT_POST, count($array));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$result = curl_exec($ch);
echo $result;

上面的代码给出了错误

404 Not Found
The server can not find the requested page:

这是我尝试

时得到的
curl_getinfo($ch);

Array
(
[url] => http://domainname.com/api/c.php
[content_type] => text/html
[http_code] => 404
[header_size] => 206
[request_size] => 73
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.00214
[namelookup_time] => 0.000309
[connect_time] => 0.000532
[pretransfer_time] => 0.000687
[size_upload] => 0
[size_download] => 2149
[speed_download] => 1004205
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0.002009
[redirect_time] => 0
[certinfo] => Array
    (
    )

[redirect_url] => 
)

但是当我直接访问网址时,就是这样     http://domainname.com/api/c.php

它在浏览器中打印结果。我在哪里做错了?

0 个答案:

没有答案