Welcome Guest, Not a member yet? Register   Sign In
A post from android with data gives 404 error
#1

Dear All,

I have a recurring problem that has stalled me for 2 weeks now. An upload of a json from an android app returns an error 404 when it calls a code igniter controller function.

Initially i assumed it was an issue with the app and after updating eclipse, changing to android studio and changing laptops and changing libraries the problem persisted.

I then concentrated on the server and realised that a direct simple php script works but a code igniter controller does not. I upgraded CI from 2.1.2 to 3.0.4 and it still returns 404. This only happens if the post had parameter values. if the post has no values it returns 200.


Code:
Simple php that works

<html>
     <body>
        Welcome
       <?php
           echo $_POST["email"];      
       ?>
    </body>
 </html>

CI code that does not work

public function __construct() {
       parent::__construct();
       //$this->load->model('Index_Model','im');
   }

public function post()
{
   echo $this->input->post('email');
}
Reply
#2

Does it show the Codeigniter styled 404 messages of is it the basic server 404 message?

You could check your server access logs to verify what url is indeed the same. If the url is correct and Codeigniter generates the 404 then you should turn on loggin in Codeigniter to try to debug it.
Reply
#3

CI 3.0.3 changelog :

Quote:Changed Config Library method base_url() to fallback to $_SERVER['SERVER_ADDR'] when $config['base_url'] is empty in order to avoid Host header injections.

i had some issues due to that change. All my pages returned 404, did you set something for $config['base_url'] ?
Reply
#4

Ive enabled the Logging and i am getting this

ERROR - 2016-02-15 02:07:16 --> 404 Page Not Found: Uniqueshuttlecoke/post

It seems it has replaced uniqueshuttle.co.ke with uniqueshuttlecoke. Removed the dots.

what might be causing this?
Reply
#5

You are trying to load a method name with a dot in it, that's not allowed. You could use the router config to reroute uniqueshuttle.co.ke to uniqueshuttle.
Reply
#6

(02-10-2016, 06:18 AM)muchemi Wrote: Dear All,

I have a recurring problem that has stalled me for 2 weeks now. An upload of a json from an android app returns an error 404 when it calls a code igniter controller function.

Initially i assumed it was an issue with the app and after updating eclipse, changing to android studio and changing laptops and changing libraries the problem persisted.

I then concentrated on the server and realised that a direct simple php script works but a code igniter controller does not. I upgraded CI from 2.1.2 to 3.0.4 and it still returns 404. This only happens if the post had parameter values. if the post has no values it returns 200.


Code:
Simple php that works

<html>
     <body>
        Welcome
       <?php
           echo $_POST["email"];      
       ?>
    </body>
 </html>

CI code that does not work

public function __construct() {
       parent::__construct();
       //$this->load->model('Index_Model','im');
   }

public function post()
{
   echo $this->input->post('email');
}

Hi , You want to send / Receive the data from android .. CI provides The Best Web services You will go for that .. refer this link ... http://code.tutsplus.com/tutorials/worki...--net-8814.
this restful Web services is easy to receive/send the json data
Manikanta
Reply
#7

(This post was last modified: 02-16-2016, 04:33 AM by keulu.)

ahhhh you want to work with the RESTfull API

okay,

so your method can't be named just "post",

try "index_post" or what you want.

you need a controller who extend REST_Controller called as you want (Api for example)

PHP Code:
class Api extends REST_Controller {
 
 
   function user_get()
 
   {
 
       // respond with information about a user
 
   }

 
   function user_post()
 
   {
 
       // update user
 
   }

 
   function user_put()
 
   {
 
       // create user
 
   }

 
   function user_delete()
 
   {
 
       // delete user
 
   }



all that routes is only one Route

http://localhost/api/user.json

afeter that, routing on method depend how you send data,

jQuery :: $ajax.post(), $ajax.delete() etc...



OKay my bad, don't read as well...

did you try to put an index.php in your url ? maybe is just the apache mod_rewrite who don't work or maybe an nginx directive who's missing
Reply
#8

I develop Android SDK app with Volley Http library.

I created CI3 server side app, but $this->input->post('email') gives NULL.

When I created PHP app without framework, $_POST['email'] gives good result.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB