Welcome Guest, Not a member yet? Register   Sign In
calling CI's Controller from external script using curl
#11

[eluser]toopay[/eluser]
If you want to provide a way, to external script, to communicate with your app, then you must build an API (Application Programming Interface). The API in this case can be conceived as the totality of all the methods publicly exposed by the classes (usually called the class interface). This means that the API prescribes the methods by which one interacts with/handles the objects derived from the class definitions.
#12

[eluser]tulipneo[/eluser]
Hi
Thanks for reply and ur valuable time.
yes u r right.
i need an interface to communicate with CI framework/controller.

it goes fine if i simply put url in browser but not through external php with curl to the link.

any suggestions, pointers or links or any where where it is implemented.
it could of great help me.

Br
Torand
#13

[eluser]toopay[/eluser]
There is one good example of REST implementation for CodeIgniter by Phil Sturgeon
#14

[eluser]tulipneo[/eluser]
Thanks.
Let me try and get back to u.
i respect.at least there is some one here to understand n suggest.

Br
Tulip
#15

[eluser]tulipneo[/eluser]
Hi
I did go through REST implementation for CodeIgniter by Phil Sturgeon.
What seems to me is its soe modification over CI framework to take in to account url mapping through cotroller.
my problem is with curl an url into CI framework cotroller for external sources.

Br
Tulip
#16

[eluser]toopay[/eluser]
I'm not clear with what you mean above, REST API is better way to serves external script which uses your resource (eg:database). For instance, at your web-blog you have a database which contain your posts data. Then, like some of famous sites services, you can provide an API to serves those external script (with apropriate access level) to access your posts data, by accessing specific url (eg:"http://yourblog.com/api/post/1").

Related with your cURL problems, i've just notice you're tried to access at port 8080, set it by curl_setopt()
Code:
<?php
$url = "http://localhost/project/index.php/messages/setInBox";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set the port here
curl_setopt($ch, CURLOPT_PORT, 8080);
$result = curl_exec($ch);
curl_close ($ch);
?>
#17

[eluser]tulipneo[/eluser]
yes i have tried to access that at port 8080 set by curl_setopt().
is that causing any problem.

Br
Tulip
#18

[eluser]toopay[/eluser]
[quote author="tulipneo" date="1303750513"]yes i have tried to access that at port 8080 set by curl_setopt().[/quote]
Then, is it working?
[quote author="tulipneo" date="1303750513"]is that causing any problem.[/quote]
If you didnt define any port, than cURL will use port 80 (the standard Web Server port), and in your case that can be a problem.
#19

[eluser]tulipneo[/eluser]
Hi
i have tried in both ways.none works.

Code:
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://127.0.0.1/KSMS/index.php/messages/setInBox');
curl_setopt($curl_handle, CURLOPT_PORT, 8080);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl_handle, CURLOPT_POST, 1);
$buffer = curl_exec($curl_handle);  
curl_close($curl_handle);

Code:
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://127.0.0.1:8080/KSMS/index.php/messages/setInBox');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl_handle, CURLOPT_POST, 1);
$buffer = curl_exec($curl_handle);  
curl_close($curl_handle);

Br
Tulip
#20

[eluser]tulipneo[/eluser]
I have a file called localtest.php.that file makes curl.

i see this output in apache access logs.
Code:
127.0.0.1 - - [25/Apr/2011:18:05:41 +0530] "POST /KSMS/index.php/messages/setInBox HTTP/1.1" 302 361
127.0.0.1 - - [25/Apr/2011:18:05:41 +0530] "GET /localtest.php HTTP/1.1" 200 -

Br
Tulip




Theme © iAndrew 2016 - Forum software by © MyBB