title: Android Rest Api Post 400 bad request
body: <p>I'm working on an app that will send a password to the server to check if it's correct, the server will return 0,1,2,3 representing different statuses
  I'm not sure where this 400 bad request is coming from. I've called the server and received the json file but I'm suspecting it's how I parsed it?
  Any help is greatly appreciated.</p>
  
  <p><strong>AN UPDATE</strong></p>
  
  <p>an update. I realize part of the mistake here is that I'm trying to send a string without converting it to a JSON file first. That is why I've been receiving "status:0" which stands for an error occurred. I've converted my string into a RegisterRequest object which contains a string variable. Now I'm receiving status 2 which stands for incorrect password. However my bad request 400 still remains. PLEASE any help or suggestion will be very helpful to me</p>
  
  <pre><code>@Headers("Content-Type: application/json")
  @POST("removed/{id}")
  RegisterResponse registerEvent(
      @Path("id") int ID, 
      @Body RegisterRequest password
  ) throws NetworkException;
  </code></pre>
  
  <p><strong>RegisterResponse class:</strong></p>
  
  <pre><code>public class RegisterResponse {
      public String status;
  }
  </code></pre>
  
  <p><strong>RegisterRequest class</strong></p>
  
  <pre><code>public class RegisterRequest {
  
      String passcode ;
  
      public RegisterRequest(String passcode)
      {
          this.passcode=passcode;
      }
  }
  </code></pre>
  
  <p><strong>call to server:</strong></p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p><strong>Make Request Adapter</strong></p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <p><strong>Error code:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>D/Boom!﹕ ---&gt; 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!﹕ ---&gt; END HTTP (17-byte body)
  D/dalvikvm﹕ GC_FOR_ALLOC freed 398K, 5% free 10098K/10528K, paused 19ms, total 19ms
  W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  I/dalvikvm﹕ Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
  W/dalvikvm﹕ VFY: unable to 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 at 0x000a
  W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
  W/dalvikvm﹕ VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
  I/dalvikvm﹕ Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
  W/dalvikvm﹕ VFY: unable to 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 at 0x000a
  D/Boom!﹕ &lt;--- 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!﹕ &lt;--- END HTTP (15-byte body)
  D/AndroidRuntime﹕ Shutting down VM
  W/dalvikvm﹕ threadid=1: thread exiting with 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
          at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:388)
          at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
          at $Proxy2.registerEvent(Native Method)
          at AndroidCall .app.ui.activities.EventListActivity.matchPasscode(ListActivity.java:387)
          at AndroidCall .app.ui.activities.EventListActivity.access$200(ListActivity.java:49)
          at AndroidCall .app.ui.activities.EventListActivity$6.onClick(ListActivity.java:302)
          at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5017)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
          at dalvik.system.NativeStart.main(Native Method)
  I/Process﹕ Sending signal. PID: 5922 SIG: 9
  </code></pre>