java - Android Rest Api Post 400 bad request -


i'm working on app send password server check if it's correct, server return 0,1,2,3 representing different statuses i'm not sure 400 bad request coming from. i've called server , received json file i'm suspecting it's how parsed it? appreciated.

an update

an update. realize part of mistake here i'm trying send string without converting json file first. why i've been receiving "status:0" stands error occurred. i've converted string registerrequest object contains string variable. i'm receiving status 2 stands incorrect password. bad request 400 still remains. please or suggestion helpful me

@headers("content-type: application/json") @post("removed/{id}") registerresponse registerevent(     @path("id") int id,      @body registerrequest password ) throws networkexception; 

registerresponse class:

public class registerresponse {     public string status; } 

registerrequest class

public class registerrequest {      string passcode ;      public registerrequest(string passcode)     {         this.passcode=passcode;     } } 

call server:

try {     registerresponse response = networkhelper.makerequestadapter(this)                .create(testapi.class).register(id, pass);          if(response.status=="1"||response.status=="3")         {             return true;         }         else             return false;     } catch (networkexception e) {         e.printstacktrace();     }    return false; } 

make request adapter

private static restadapter.builder makerequestadapterbuilder(final context context, errorhandler errorhandler, string datetimeformat)     {         requestinterceptor requestinterceptor = new requestinterceptor()         {             @override             public void intercept(requestinterceptor.requestfacade request)             {                 request.addheader("authorization", appprefs.getinstance(context).getsessiontoken());             }         };          gson gson = new gsonbuilder().setdateformat(datetimeformat).create();         gsonconverter gsonconverter = new gsonconverter(gson);          restadapter.builder builder = new restadapter.builder()                 .setrequestinterceptor(requestinterceptor).setconverter(gsonconverter)                 .setloglevel(restadapter.loglevel.full).setlog(new androidlog("boom!"))                 .setendpoint(base_url);          if(errorhandler != null)         {             builder.seterrorhandler(errorhandler);         }          if(instance == null)         {             instance = new okclient(maketimeoutclient(read_timeout, connect_timeout));         }         builder.setclient(instance);          return builder;     } 

error code:

d/boom!﹕ ---> http post https://serverurl/29520 d/boom!﹕ authorization: token 4a712131231299ba5bd0737163bcf1d6ff5325b4ef d/boom!﹕ content-type: application/json d/boom!﹕ content-length: 17 d/boom!﹕ {"passcode":"55"} d/boom!﹕ ---> end http (17-byte body) d/dalvikvm﹕ gc_for_alloc freed 398k, 5% free 10098k/10528k, paused 19ms, total 19ms w/dalvikvm﹕ vfy: unable find class referenced in signature (ljava/nio/file/path;) w/dalvikvm﹕ vfy: unable find class referenced in signature ([ljava/nio/file/openoption;) i/dalvikvm﹕ not find method java.nio.file.files.newoutputstream, referenced method okio.okio.sink w/dalvikvm﹕ vfy: unable resolve static method 29588: ljava/nio/file/files;.newoutputstream (ljava/nio/file/path;[ljava/nio/file/openoption;)ljava/io/outputstream; d/dalvikvm﹕ vfy: replacing opcode 0x71 @ 0x000a w/dalvikvm﹕ vfy: unable find class referenced in signature (ljava/nio/file/path;) w/dalvikvm﹕ vfy: unable find class referenced in signature ([ljava/nio/file/openoption;) i/dalvikvm﹕ not find method java.nio.file.files.newinputstream, referenced method okio.okio.source w/dalvikvm﹕ vfy: unable resolve static method 29587: ljava/nio/file/files;.newinputstream (ljava/nio/file/path;[ljava/nio/file/openoption;)ljava/io/inputstream; d/dalvikvm﹕ vfy: replacing opcode 0x71 @ 0x000a d/boom!﹕ <--- http 400 https://serverurl/29520 (489ms) d/boom!﹕ allow: post, options d/boom!﹕ cache-control: no-cache="set-cookie" d/boom!﹕ content-type: application/json d/boom!﹕ date: sat, 25 apr 2015 14:19:12 gmt d/boom!﹕ server: apache/2.4.7 (ubuntu) d/boom!﹕ set-cookie: awselb=b19bd105182d026362b8bc00141d5791f1205a08caa1f992d8f8ec9b69bb363d3418c9476b70a93f8d096b34c3d75087deec69eb5c6d2c30536be30bc1e0a0ebb500881d9d;path=/;max-age=60 d/boom!﹕ vary: accept,cookie d/boom!﹕ x-frame-options: sameorigin d/boom!﹕ content-length: 15 d/boom!﹕ connection: keep-alive d/boom!﹕ okhttp-selected-protocol: http/1.1 d/boom!﹕ okhttp-sent-millis: 1429971549555 d/boom!﹕ okhttp-received-millis: 1429971549598 d/boom!﹕ {"status": "2"} d/boom!﹕ <--- end http (15-byte body) d/androidruntime﹕ shutting down vm w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x415c7ba8) d/dalvikvm﹕ gc_for_alloc freed 439k, 5% free 10173k/10644k, paused 20ms, total 20ms d/dalvikvm﹕ gc_for_alloc freed 494k, 5% free 10187k/10716k, paused 20ms, total 20ms e/androidruntime﹕ fatal exception: main process: androidcall , pid: 5922 retrofit.retrofiterror: 400 bad request         @ retrofit.restadapter$resthandler.invokerequest(restadapter.java:388)         @ retrofit.restadapter$resthandler.invoke(restadapter.java:240)         @ $proxy2.registerevent(native method)         @ androidcall .app.ui.activities.eventlistactivity.matchpasscode(listactivity.java:387)         @ androidcall .app.ui.activities.eventlistactivity.access$200(listactivity.java:49)         @ androidcall .app.ui.activities.eventlistactivity$6.onclick(listactivity.java:302)         @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:166)         @ android.os.handler.dispatchmessage(handler.java:102)         @ android.os.looper.loop(looper.java:136)         @ android.app.activitythread.main(activitythread.java:5017)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595)         @ dalvik.system.nativestart.main(native method) i/process﹕ sending signal. pid: 5922 sig: 9 

i've figured out. handling wrong exception , api returning 400 instead of 401 senting wrong passcode. i've changed call server network exception error exception error.

thank help.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -