请需要你的帮助!我使用 cURL 发送帖子,但响应为空白(布尔值 false)。如果我像按浏览器一样在浏览器上发布数据,https://www.example.com/myaccount/transfer.php?username=usernamer&password=pass&deposit=5
则会显示以下结果:
1 0 success Your account has been deposited
.
当我看到浏览器源代码时,结果是:
<?xml version="1.0" encoding="utf-8"?>
<TransferResponse>
<version>1</version>
<result>0</result>
<resultstring>success</resultstring>
<description>Your account has been deposited</description>
</TransferResponse>
让我附上我的 cURL 代码:
<?php
$config = array
(
"url" => "https://www.example.com/myaccount/",
"transfer" => "transfer.php",
"browser" => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);
$postFields = "username=username&password=pass&deposit=5";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url'] . $config['transfer']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/cert/GeoTrustGlobalCA.crt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config['browser']);
curl_setopt($ch, CURLOPT_REFERER, $config['url']);
curl_setopt($ch, CURLOPT_HEADER, true);
$content = curl_exec($ch);
var_dump($content);
var_dump(curl_getinfo($ch));
curl_error($ch);
curl_close($ch);
echo $content;
?>
请帮助我在 cURL 中获得结果。我尝试了很多方法。我已经连续上网 2 天了。最后我决定在这里问。有人可以找出问题所在吗?执行以下操作:
- 命令行将
http
(不是 https)的结果显示为 xml。 - 命令行返回
https
(not http)的结果如下: Failed: Error Number: 60. Reason: SSL证书问题,验证CA证书是否OK。详细信息:错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 http
(不是 https)的 cURL 结果只是重定向 www.example.com 的警告页面var_dump($content); and var_dump(curl_getinfo($ch));
结果是:boolean false array (size=26) 'url' => string ' https://www.example.com/myaccount/transfer.php' (length=46) 'content_type' => null 'http_code' => int 0 'header_size' => int 0 'request_size' => int 0 'filetime' => int -1 'ssl_verify_result' => int 0 'redirect_count ' => int 0 'total_time' => float 1.451 'namelookup_time' => float 0 'connect_time' => float 0 'pretransfer_time' => float 0 'size_upload' => float 0 'size_download' => float 0 'speed_download' => 浮动 0 'speed_upload' => 浮动 0 'download_content_length' => 浮动 -1 'upload_content_length' => 浮动 -1 'starttransfer_time' => 浮动 0 'redirect_time' => 浮动 0 'certinfo' => 数组(大小= 0) 空'primary_ip' => string '177.70.43.10' (length=11) 'primary_port' => int 443 'local_ip' => string '192.168.11.9' (length=0) 'local_port' => int 0 'redirect_url' =>字符串''(长度=0)