i'm trying use retrofit restful webservice. seems alright, somehow when run code returns this
method not found. retrofit 404 error
here webservices code
public function processapi() { $func = strtolower(trim(str_replace("/","",$_post['request']))); if ((int)method_exists($this,$func) > 0) { $this->$func(); } else { // if method not exist in class, response "page not found". $this->response('method not found',404); } } private function login() { // cross validation if request method post else return "not acceptable" status if ($this->get_request_method() != "post") { // if invalid inputs "bad request" status message , reason $error = array('status' => "0", "msg" => "bad request"); $this->response($this->json($error), 406); } // input validations if (empty($email) , empty($password)) { $error = array('status' => "0", "msg" => "invalid email address or password"); $this->response($this->json($error), 400); } } public class objectpost { @serializedname("request") string request; @serializedname("email") string event_id; public void setrequest(string request) { this.request = request; } public void setevent_id(string event_id) { this.event_id = event_id; } } and here android request code
public class restclient { public interface clientinterface { @post(config.login_url) void login(@body objectpost mobject, callback<loginbeans> callback); } public static clientinterface initrestadapter() { okhttpclient client = new okhttpclient(); return (clientinterface) new restadapter.builder() .setloglevel(restadapter.loglevel.full) .setclient(new okclient(client)) .setendpoint(config.server_url) .build() .create(clientinterface.class); } }
the value in
config.login_url
is incorrect. please remember that
config.server_url
must contain base url address. e.g. http://www.server.com/ (also please note slashes important)
next, in attribute must remainder of specific method appended on base url. e.g. if method want call login, should
@post("/login")
once again, not kidding slashes.
remember if query parameter sent through null, retrofit ignores (you may face problem later).
if need further help, have loglevel set full, please add logcat question can see happening.
Comments
Post a Comment