【发布时间】:2026-01-30 09:00:01
【问题描述】:
我已经阅读了很多文章和讨论(也在 * 中),但我还没有找到解决方案。
我有一个对外部网站执行操作的表单。
我需要提交我的表单以获取该站点的响应(我的 http 请求的响应标头很好)。可能吗?
我已尝试使用 curl (CURLOPT_RETURNTRANSFER true),但我的以下代码可能有问题:
$post_data['xx'] = 'xxx';
$post_data['yy'] = 'yyy';
$post_data['zz'] = '13-12-2015';
$postData = '';
foreach($post_data as $k => $v)
{
$postData .= $k . '='.$v.'&';
}
rtrim($postData, '&');
$url = 'http://......';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $http;
curl_close ($ch);
返回为“0”。
谢谢!
【问题讨论】:
-
究竟是什么不工作?
var_dump($http)? -
我有 0 作为来自 $http 的响应。有任何想法吗。我尝试过使用 var_dump,但收到“int 0”。 @德文
-
运行
print_r(curl_getinfo($ch));以获取更多信息,帮助您解决问题。 -
I have already tried it but it returns an array with the information of my request- 多么奇怪的巧合,我想知道是否提供该信息 通过将其添加到问题 可能是 @Emil 要求您这样做的原因。惊奇。 -
@Gio 如果http代码为0,一般表示连接失败。
标签: php post curl http-response-codes