Welcome Guest, Not a member yet? Register   Sign In
Rest API Codeigniter. CORS PROBLEM [SOLVED]
#5

(This post was last modified: 04-15-2018, 02:32 PM by theedo.)

Ok, I tried to host the frontend (reactjs) on a server with an accessible domain, then I tried one request and it doesn't work.
I've always this error: [Image: 9f1901669320d69ae4bec007a24a76ac.png]

UPDATE: SOLVED!

So, I was using IIS, so I added to my web.config:

Code:
<httpProtocol>
 <customHeaders>
   <add name="Access-Control-Allow-Origin" value="*" />
   <add name="Access-Control-Allow-Headers" value="Content-Type" />
   <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
 </customHeaders>
</httpProtocol>
then I changed my controller to that
PHP Code:
<?php
/**
 * Created by PhpStorm.
 * User: Edoardo
 * Date: 15/04/2018
 * Time: 18:26
 */

require APPPATH 'libraries/REST_Controller.php';

class 
Login extends REST_Controller
{

 
   public function __construct($config 'rest')
 
   {
 
       parent::__construct($config);


 
   }

 
   public function index_post(){
 
       echo json_encode(array("hey" => "hey!"));
 
   }

 
   public function index_options() {
 
       return $this->response(NULLREST_Controller::HTTP_OK);
 
   }



and now it works!
Reply


Messages In This Thread
RE: Rest API Codeigniter. - by InsiteFX - 04-15-2018, 01:02 PM
RE: Rest API Codeigniter. - by theedo - 04-15-2018, 01:58 PM
RE: Rest API Codeigniter. - by InsiteFX - 04-15-2018, 02:04 PM
RE: Rest API Codeigniter. - by theedo - 04-15-2018, 02:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB