0
votes

I write a controller in CakePhp-2.9 named API to access outside. Controller Code:

class APIController extends AppController
{
var $name = 'API';
var $cache_dir = 'img/cache';
var $cache_width = 400;
public $msgs = array();

public function beforeFilter()
{
    parent::beforeFilter();
         $this->Auth->allow('ecall_request','ecall_callback','testlog','ecall_request_test','ecall_callback_test');

} 


public function ecall_request()
{   


Cache::write("test_request".time(),$this->request->data);
if($this->request->is('post'))
{
 // my code here
}
 }
}

And i tested "http://localhost/dentech/api/ecall_request" on POSTMAN successfully, But when i upload it on server at https://dentech.com/api/ecall_request it does not access and gives 404 error.

htaccess code is:

<IfModule mod_rewrite.c>
RewriteEngine on
# Uncomment if you have a .well-known directory in the root folder, e.g. for the Let's Encrypt challenge
# https://tools.ietf.org/html/rfc5785

RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

1
Can you access the controller method when typing the URL into the browser? Since you are seemingly trying to build an API I think you are making cross origin requests (CORS). You might need to add header('Access-Control-Allow-Origin: *'); in order to allow CORS requests. - Gegenwind
no, not able to access in browser - Surya prakash Patel
Yes @user2672106 i am trying to build an API to access via cronjob - Surya prakash Patel
the link is not available through this dentech.com/api/ecall_request,, upon checking the domain it should be access without "https" dentech.com/api/ecall_request and the url still not found.. Are you changing hosting provider? or did you upload the cakephp files already and over ride the existing files in the server? If you already uploaded it then the problem is not yet pointed on the new server..... the website is in .aspx extension dentech.com/home.aspx - distromob
@SuryaprakashPatel: Your APIController is in capital letters, the URL you copied is not. Maybe that is the issue. If your local dev system runs on windows (not case sensitive) and your server on Linux (case sensitive) this might be the issue. - Gegenwind

1 Answers

0
votes

Updated from comments: The reason for the 404-error is that the controller name in the URL has to be in uppercase characters. Instead of

https://dentech.com/api/ecall_request

You need to use

https://dentech.com/API/ecall_request

The fact that it works on localhost but not on the server is the difference in the operating system. Windows (often used locally) is not case-sensitive, while Linux (usually the servers OS) is case-sensitive.