Example: (Send a post request with specific header):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$params = array( 'client_id' => $this->clientID, 'redirect_uri' => $this->redirectURI ); //Notice: value for header array is strings, not key/value pairs. $request = array( CURLOPT_HTTPHEADER => array( 'Content-type: application/x-www-form-urlencoded', 'param1:value1', 'param2:value2' ), CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_RETURNTRANSFER => true //Important! ); $ch = curl_init('http://REQUEST URL'); curl_setopt_array($ch, $request); $result = curl_exec($ch); //$info = curl_getinfo($ch); $data = json_decode($result); |
Error Handling
顯示錯誤: curl_error($ch)
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
如果出現上面這個問題:
Solution 1:
CURLOPT_SSL_VERIFYPEER => false
http://blog.kejyun.com/2012/12/Facebook-PHP-SDK-SSL-Certificate-Problem-Solution.html
Solution 2: 表示Cert有問題,請參考:
http://davidwalsh.name/php-ssl-curl-error
http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
總之要加上下面這個參數:
curl_setopt($ch,CURLOPT_CAINFO,’d:\path\cert.pem’);
cert.pem下載網址: http://curl.haxx.se/docs/caextract.html
Reference:
hello there and thank you for your information – I have definitely picked up anything new from right here.
I did however expertise a few technical issues using this site, as I experienced to reload
the web site a lot of times previous to I could get it to load correctly.
I had been wondering if your web host is OK?
Not that I’m complaining, but sluggish loading instances times will often affect your placement in google and can damage your high quality score if advertising and marketing with Adwords. Well I’m adding this RSS to my email and can look out
for a lot more of your respective fascinating content.
Ensure that you update this again soon.