This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

Php Curl Functions For Post And Get Request Using Codeigniter

Php Curl Functions For Post And Get Request Using Codeigniter DOM parser,html,php,preg_replace,tags Php Curl Functions For Post And Get Request Using Codeigniter

Install the curl library from https://github.com/philsturgeon/codeigniter-curl
CodeIgniter-cURL is a CodeIgniter library which makes it easy to do simple cURL requests and makes more complicated cURL requests easier too.

 //load the Curl library $this->load->library('Curl'); //Request using POST Method $url = 'http://postexample.com/json.php'; echo $this->curl->simple_post($url, false, array(CURLOPT_USERAGENT => true)); //Request using POST Method $get_url = http://getexample.com/json.php; echo $this->curl->simple_get($get_url, false, array(CURLOPT_USERAGENT => true)); 
It is very important to set CURLOPT_USERAGENT, otherwise many servers may refuse your request if you don't pass user agent.
 //PHP version, you can put anyvalue for CURLOPT_USERAGENT, but it shouldn't be empty or blank. curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
I tried without setting CURLOPT_USERAGENT in GOOGLE CHROME, it didn't worked. I spent more than 4 hours to find a solution, why it is not returning the result. Finally, I found this post http://www.silverphp.com/php-curl-function-for-post-and-get-request.html and try with my luck. And it worked. :)

0 Response to "Php Curl Functions For Post And Get Request Using Codeigniter"

Posting Komentar

Contact

Nama

Email *

Pesan *