• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making POST requests in CI

Is there any easy way to make POST requests in CI?

Do I have to use the cURL facility to do this?

Thank You!

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:

public function index(){

There are probably other ways. But I like simple.

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.

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!

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.st...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.

Thanks skunkbad.

I'll refer to the material.

Sadly cURL is not available with all hosters...for now I would stick to fopen().

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..

Have a look at my twitter library (link is in my signature). It uses fsockopen, fwrite and fgets to perform GET and POST requests.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.