Making POST requests in CI - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Making POST requests in CI (/showthread.php?tid=25936) |
Making POST requests in CI - El Forum - 12-31-2009 [eluser]chamila[/eluser] Is there any easy way to make POST requests in CI? Do I have to use the cURL facility to do this? Thank You! Making POST requests in CI - El Forum - 12-31-2009 [eluser]wowdezign[/eluser] You mean without a form? Was trying to implement pagination on a page with a result set and a search refining form and ran into a problem with the pagination (since there isn't any POST data sent with the link). I knew query strings were out of the question since the customer didn't like "messy URLs". I ended up maintaining the state with the Session library. If you are talking about ajax calls, I just create an ajax controller that I can go to via a url and have it display the results. In my index method on the ajax controller I use: Code: public function index(){ There are probably other ways. But I like simple. Making POST requests in CI - El Forum - 12-31-2009 [eluser]BrianDHall[/eluser] I'm not aware of any special functionality available in CI, just CURL makes it a lot easier. You don't have to use CURL, but it certainly makes things a lot easier. There is a CURL library for CI, just search the wiki - I think Phil Sturgeon made it. Makes dealing with CURL require much less code, I really like his implementation. Still, it requires your PHP have CURL available. Making POST requests in CI - El Forum - 12-31-2009 [eluser]chamila[/eluser] Thanks a lot for the replies. wowdezign, I meant making POST requests without a form. I'm using the RPXNow OpenID facility from JanRain, and it requires making a POST request to one of their links. I think I'll use CURL. I found an article here (http://codeigniter.com/wiki/Curl_library/). It is much simpler and needs less code. Thanks guys! Making POST requests in CI - El Forum - 12-31-2009 [eluser]skunkbad[/eluser] You don't need cURL if you just need a simple POST. You could use PHP's file_get_contents() function, and set the third parameter to a stream context. This is documented in the PHP manual at http://php.net/manual/en/function.file-get-contents.php and http://www.php.net/manual/en/function.stream-context-create.php . You could also use fopen(). Please note the comments at the bottom of both pages I mentioned, and you will find a solution to meet your needs. Also, cURL is an essential if you are a developer. You should take the time to learn how to use cURL, because it can do a lot for you. Making POST requests in CI - El Forum - 12-31-2009 [eluser]chamila[/eluser] Thanks skunkbad. I'll refer to the material. Making POST requests in CI - El Forum - 01-01-2010 [eluser]davidbehler[/eluser] Sadly cURL is not available with all hosters...for now I would stick to fopen(). Making POST requests in CI - El Forum - 01-01-2010 [eluser]Fabdrol[/eluser] CURL is the easiest option, at least, if your host supports it and you're using the curl lib. ([url="http://codeigniter.com/wiki/Curl_library/"]WIKI: CURL[/url]) Personally, I'm not really fond of file_get_contents. It's meant for use with files in your local filesys, and it seems unsemantic to use it for POST requests. Although, it's not forbidden or so.. Making POST requests in CI - El Forum - 01-01-2010 [eluser]davidbehler[/eluser] Have a look at my twitter library (link is in my signature). It uses fsockopen, fwrite and fgets to perform GET and POST requests. |