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

[eluser]toopay[/eluser]
Did you post some data? why you includes this line
Code:
curl_setopt($curl_handle, CURLOPT_POST, 1);
if you're need to uses 'POST' method, then you should include this after above line
Code:
// include $_POST array
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
#22

[eluser]tulipneo[/eluser]
Hi
Http error code 302 means "moved temporarily.in other words i have a feeling that its trying to access some thing and does not follow CI's style of calling with controller/class/method.

Br
Tulip
#23

[eluser]tulipneo[/eluser]
Hi
Thanks for ur reply.
i removed the post statement
ie

Code:
curl_setopt($curl_handle, CURLOPT_POST, 1);

and still no luck.

and now i see in apache log as bellow.
Code:
127.0.0.1 - - [25/Apr/2011:18:13:11 +0530] "GET /KSMS/index.php/messages/setInBox HTTP/1.1" 302 -
127.0.0.1 - - [25/Apr/2011:18:13:11 +0530] "GET /localtest.php HTTP/1.1" 200 -

Br
Tulip
#24

[eluser]toopay[/eluser]
Did you put some redirect() inside 'setInBox' function? Show your 'message' controller.
#25

[eluser]tulipneo[/eluser]
My controller is as bellow.

Code:
<?php
class Messages extends MY_Controller {

    function Messages()
    {
        parent::MY_Controller();
        
        // session check
        if($this->session->userdata('loggedin')==NULL) redirect('login');
    }
    public function setInBox()
        {    
        log_message('info', 'Inside MethodXXXXXXXXXXXXX');
        $out_connection = mysql_connect("127.0.0.1","root","sql") or die ("Could not connect to the server: " . mysql_error());
        if($out_connection)
        {
            echo "connection successfull";
        }
        $in_db = "sms";
        $dummy_db = mysql_select_db($in_db, $out_connection) or die ("Could not select database: " . mysql_error());
        $sql_query= "insert into hoax(name) values('neo')";
        $result = mysql_query($sql_query) or die ( mysql_error());
          
        }
    ?>

inside the method i have put a log message and a test data to database to make sure that this is called.

Br
Tulip
#26

[eluser]toopay[/eluser]
Code:
if($this->session->userdata('loggedin')==NULL) redirect('login');
Thats why you receive 302 in header response.

In addition, you could do the database stuff on your model, using CI DB class, rather than manual connection like that. Also, consider what i suggest before, to using an API!
#27

[eluser]tulipneo[/eluser]
Hi
I was doing that way because i was already loged in and trying in another window.it should work because if i directly place the link ie http://127.0.0.1/KSMS/index.php/messages/setInBox in browser it works fine but not through curl.
anyway i commented that
ie if($this->session->userdata('loggedin')==NULL) redirect('login');
and still it did not work.

br
tulip
#28

[eluser]toopay[/eluser]
If you already login, then make a curl call within that app, it should be worked. But, if you called from another app, then it was another story.
[quote author="tulipneo" date="1303754745"]
anyway i commented that
ie if($this->session->userdata('loggedin')==NULL) redirect('login');
[/quote]
make sure you use 'GET' method instead 'POST'.
#29

[eluser]toopay[/eluser]
Btw, i use Fiddler as web debugger. It may help you too, to inspect all HTTP(S) traffic, set breakpoints, and deals with incoming or outgoing data.
#30

[eluser]tulipneo[/eluser]
Hi
Yes i use GET

see logs bellow:

Code:
127.0.0.1 - - [25/Apr/2011:18:45:54 +0530] "GET /KSMS/index.php/messages/setInBox HTTP/1.1" 302 -
127.0.0.1 - - [25/Apr/2011:18:45:54 +0530] "GET /localtest.php HTTP/1.1" 200 -

br
Tulip




Theme © iAndrew 2016 - Forum software by © MyBB