我尝试使用 PHP Curl 通过 post 方法提交值。但它不适用于 HTTPS 页面。任何人都会查看我的以下代码并检查我做错了什么。
$url = 'https://www.whoisxmlapi.com/user/create.php';
$fields = array(
'username' => urlencode("check123"),
'email' => urlencode("check123@gmail.com"),
'password' => urlencode("password"),
'password_confirmation' => urlencode("password"),
'firstname' => urlencode("firstname"),
'lastname' => urlencode("lastname"),
'organization' => urlencode("organization"),
'captcha' => urlencode("captcha")
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);