Search code examples
javaandroidrestvisual-studio-codepostman

Rest api is returning bad request using VSCode or postman while it is working with my android app?


My problem is opposite of most of problems that have been posted in web like Why is my API working with Postman but not working with Java Get request or HttpClient returning Bad Request while Postman is working fine

My rest API is working very well on my java android app but it fail to login using Thunder Client VSCode extension or desktop postman running with Xampp. All of these API tools returning Status: 400 Bad Request and can't verify even first field of login form while in android app it has no problem.

What has caused this problem?

I am using retrofit2 for my working java codes: (phone = 123456, password = 123456789)

@POST("http://localhost/myapp/index.php/auth/login")
    ApiResponse<AuthResponse> login(@Body UserLogin userLogin);

and in VSCode

enter image description here

and this is the my Xampp details:

enter image description here


Solution

  • Your app is doing something that you are missing in the Postman call. For example:

    • Missing headers
    • Fields
    • Content formatting

    To solve this you'll need to see the full request that your app is making - often default logging is not enough.

    There are a few ways to do this:

    1. Increase logging client-side (eg via OKHttp logging interceptor)
    2. Check on the server side.
    3. Use a proxy (Fiddler, Charles etc.) to sniff network traffic

    I would go with 1) as the simplest. The likelihood is you are missing some headers or similar.