编码点火器 - 通过 URL 发送数据并获得响应


Codeigniter - sending data via URL and getting response

我试图做的是将一些数据发送到 url 并获得类似"成功"的响应,指示数据是在 codeigniter 中接收的。我是否需要在代码点火器中配置 API 来测试它。我尝试了以下代码,但没有得到预期的结果。值得一提的是,我在编码点火器和 php 方面很新。

控制器 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;
    }
}
?>

并且模型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;
        }
      }
      ?>
After url encoing Space[ ] can encoded as + sign.you have to manually replace as %20,then after execute your URL.
public function sendSMS($mobile,$code)
{
      $stream_options = array(
    'http' => array(
       'method'  => 'GET',
        ),
    );
             $context  = stream_context_create($stream_options);
     $url="http://api.smsbrain.in/1.2/appsms/send.php?user=satish123&passwd=123456&senderId=SATISH&recipients=".$mobile."&message=Your%20Verification%20code%20for%20facebook%20is%20".$code.".";
     //echo "URL".$url;
     $response = file_get_contents($url, null, $context);

    echo print_r($response);
}