php - cURL not fetching the expected POST response - error 405 -
i need fetch several charts highcharts export server (since haven't implemented feature on own server yet).
highcharts shows clear example here: http://export.highcharts.com/demo
i tried simulate form using curl command linux, successfully.
but, when trying run curl php (specifically cakephp controller), http error:
http status 405 - request method 'post' not supported
something wrong, since post method worked interactivelly navigator , curl command.
also, tested php script pointing posttestserver.com, site intended debugging result of post requests. result of test here: http://www.posttestserver.com/data/2014/03/10/10.18.221071980127
this code of method of cakephp controller:
public function obtenir() { $ch = curl_init("http://export.highcharts.com/demo"); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, array( "content" => "options", "options" => "%7b%0d%0a%09xaxis%3a+%7b%0d%0a%09%09categories%3a+%5b%27jan%27%2c+%27feb%27%2c+%27mar%27%2c+%27apr%27%2c+%27may%27%2c+%27jun%27%2c+%27jul%27%2c+%27aug%27%2c+%27sep%27%2c+%27oct%27%2c+%27nov%27%2c+%27dec%27%5d%0d%0a%09%7d%2c%0d%0a%09series%3a+%5b%7b%0d%0a%09%09data%3a+%5b29.9%2c+71.5%2c+106.4%2c+129.2%2c+144.0%2c+176.0%2c+135.6%2c+148.5%2c+216.4%2c+194.1%2c+95.6%2c+54.4%5d%0d%0a%09%7d%5d%0d%0a%7d%3b%0d%0a", "type" => "image%2fpng", "width" => "", "scale" => "", "constr" => "chart", "callback" => "function%28chart%29+%7b%0d%0a%09chart.renderer.arc%28200%2c+150%2c+100%2c+50%2c+-math.pi%2c+0%29.attr%28%7b%0d%0a%09%09fill+%3a+%27%23fcffc5%27%2c%0d%0a%09%09stroke+%3a+%27black%27%2c%0d%0a%09%09%27stroke-width%27+%3a+1%0d%0a%09%7d%29.add%28%29%3b%0d%0a%7d%0d%0a%09%09%09", )); curl_setopt($ch, curlopt_httpheader, array("content-type: application/x-www-form-urlencoded; charset=utf-8")); curl_setopt($ch, curlinfo_header_out, true); curl_setopt($ch, curlopt_returntransfer, true); $page = curl_exec($ch); $head = curl_getinfo($ch, curlinfo_header_out); debug($head); debug($page); curl_close($ch); }
the result of debug($page) html formatted text significant content:
http status 405 - request method 'post' not supported
what doing wrong?
thank much.
use http_build_query()
post on post parameter array. otherwise recognized multipart form posting.
curl_setopt($ch, curlopt_postfields, http_build_query( array(...) ));
please make sure post
url correct.
Comments
Post a Comment