Php 使用curl&;文件\u获取\u内容:连接被拒绝

Php 使用curl&;文件\u获取\u内容:连接被拒绝,php,api,curl,post,file-get-contents,Php,Api,Curl,Post,File Get Contents,我正在尝试将数据使用curl&file\u get\u内容发布到“url1”,但出现了一些错误,连接被拒绝,但将数据发布到“url2”是正常的 卷曲: $post = ['data1'=>'A','data2'=>'B']; $ch = curl_init('url1'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = c

我正在尝试将数据使用curl&file\u get\u内容发布到“url1”,但出现了一些错误,连接被拒绝,但将数据发布到“url2”是正常的

卷曲:

$post = ['data1'=>'A','data2'=>'B'];
$ch = curl_init('url1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
curl:(7)无法连接到url1端口82:连接被拒绝

文件\u获取\u内容:

$data = array('data1'=>'A','data2'=>'B');
$options = array(
                'http' => array(
                    'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                    'method'  => 'POST',
                    'content' => http_build_query($data),
                    ),
            );
$context  = stream_context_create($options);
$result = file_get_contents('url1', false, $context);
var_dump($result);
警告:文件获取内容(url1):无法打开流:连接被拒绝


我是否犯了此代码错误?

此问题似乎与目标服务器或防火墙配置有关。您可以检查目标防火墙设置或使用目标服务器上所需的所有标头。首先,尝试使用并为原始标题添加适当的值


如果问题不是防火墙,你可以看看。

put
var\u dump(curl\u getinfo($ch))
就在
curl\u close
之前,你还忘了
curl\u setopt($ch,CURLOPT\u POST,1)
另外,端口82不是网站的默认端口(如80),您确定必须向82发布任何内容吗?@user1597430我已经使用curl\u getinfo&curlopt\u POST,但仍然遇到相同的问题,url目标是use port 82curl\u getinfo是一个调试函数,您必须检查HTTP代码和服务器响应以了解问题