我已经安装了curl。我系统上的配置是
cURL support enabled
cURL Information 7.35.0
Age 3
我在我的项目中编写的代码是:
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($curl, CURLOPT_SSLVERSION,6);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($curl, CURLOPT_URL, $submit_url);
$curl_execute = curl_exec($curl);
curl_close($curl);
在服务器上正常工作时,它没有给我本地机器的价值。有什么问题? 我的PHP版本是
5.5.9-1ubuntu4.5
我正在使用ubuntu 13.10 我的本地机器有什么问题?我错过了什么。请建议做什么?
编辑: 如果我错过任何信息,请通知我..我第一次使用卷曲。
答案 0 :(得分:0)
首先正确定义URL并发布值,我添加了示例,请尝试以下操作:
// define url examples
$submit_url = 'http://localhost/phptest/service.php';
// post fields examples
$postfields = 'name=foo&pass=bar&format=json';
// Start the process:
$curl = curl_init();
// Tell cURL to fail if an error occurs:
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
// Allow for redirects:
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
// Assign the returned data to a variable:
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Set the timeout:
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
// Use POST:
curl_setopt($curl, CURLOPT_POST, 1);
// Set the POST data:
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_URL, $submit_url);
// Execute the transaction:
$result = curl_exec($curl);
// Close the connection:
curl_close($curl);
// Print the results:
print_r($result);