Codeigniter Запрещено публиковать данные в методе REST API post через URL. он показывает ошибку как неизвестный метод

Я пытаюсь отправить данные через URL, как

HTTP: //localhost/api/index.php/society/ дата = 20/04/2017&s_name = SSR

но он показывает сообщение об ошибке:

{«status»: false, «error»: «Неизвестный метод»}

Когда я тестирую с postman или же advance rest client Приложение работает нормально, данные публикуются и обновляются.

URL: Http: //localhost/api/index.php/society

Мой контроллер ….

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . 'libraries/REST_Controller.php';

use Restserver\Libraries\REST_Controller;

class Society extends REST_Controller
{

function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Society_model');
}

public function index_get()
{
$data = $this->Society_model->society_get();
$this->response($data);
}

public function index_post()
{

$data = array(
'date' =>$this->post('date'),
'society_name' => $this->post('s_name'),
'society_group' => $this->post('g_name'),
'contact_name' => $this->post('c_name'),
'mobile_no' => $this->post('mobile'),
'address' => $this->post('address'),
'city' => $this->post('city'),
'state' => $this->post('state'),
'pincode' => $this->post('pincode'),
'email_id' =>$this->post('email')
);

$this->Society_model->insert($data);

$this->set_response($data, REST_Controller::HTTP_CREATED);
}
}

Моя модель ….

<?php

class Society_model extends CI_Model
{

function __construct()
{
parent::__construct();
}

public function society_get(){
$this->db->select('*');
$this->db->from('society_contact');
$result = $this->db->get();
return $result->result();
}

public function insert($data)
{
if ($this->db->insert("society_contact", $data))
{
return true;
}
}
}

0

Решение

общество это название функции вашей модели индекс название
HTTP: //localhost/api/index.php/index/ дата = 20/04/2017&s_name = SSR

0

Другие решения

Вы не можете использовать метод POST через браузер. Вы должны использовать POSTMAN или другой клиент REST. URL в браузере позволяет только получать информацию.

Пожалуйста, обратитесь к этому сообщению Как вручную запустить HTTP POST-запросы с помощью Firefox или Chrome?

Также ваш URL HTTP: //localhost/api/index.php/society/ дата = 20/04/2017&s_name = SSR

это не правильно, потому что, когда вы добавили ?something=something, это параметр, также если вы добавили / это отдельные части URL. Вот почему вы получаете Неизвестный метод.

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector