what i am trying to do is send some data to a url and get a response like "success" that indicates that data is received in codeigniter. Do i need to configure an api in the codeigniter to test that. I tried the following code but not getting the expected result. To mention I am pretty new in codeigniter and php.
controller xmlPost.php
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class XmlPost extends CI_controller
{
public function index()
{
$this->load->model('xml_model','message');
$this->message->source = "14045" ;
$this->message->dst = "08887654657";
$this->message->msg = "Hi, this is test";
$this->message->url = 'http://localhost/codeigniter1/index.php/receive';
$data = $this->message->Send();
echo $data;
}
}
?>
and the model is xml_model.php
<?php
Class Xml_model extends CI_Model {
var $source; //Source address
var $dst; //Destination
var $msg; // Message
var $url;
var $api_url;
function __construct() {
parent::__construct();
}
function Send(){
$this->api_url = 'http://localhost/codeigniter1/index.php/receive';
$params = $this->source.'&destinationaddr='.$this->dst.'&shortmessage='.urlencode($this->msg).' '.urlencode($this->url).'';
$post_data = array(
"sourceaddr" => $params,
);
$stream_options = array(
'http' => array(
'method' => 'POST',
),
);
$context = stream_context_create($stream_options);
$response = file_get_contents($this->api_url, null, $context);
return $response;
}
}
?>
codeigniter1/index.php/receive?receive.php? you can directly call the page and see the output.