0

I'm making a mock postman collection to use in an android app. I'm starting with a simple {{url}}/user/login endpoint and seem to be having trouble with the Content-Type header. Retrofit adds this by default as application/json; charset=UTF-8, which is fine but the problem is the content body matcher can't seem to match the body of my requests. In postman this doesn't work either, my examples are -

Successful Request

Request Headers 
Content-Type - application/json

Request Body
{
    "username": "user1",
    "password": "123"
}

Response Body 
{
    "first_name" : "user",
    "last_name": "one"
}

(I'm using the x-mock-match-request-body header in both requests from retrofit and postman).

This works perfectly fine and returns as you'd expect, when I send a request from my app the request is logged as -

D/OkHttp: --> POST {{url}}/user/login http/1.1
D/OkHttp: Content-Type: application/json; charset=UTF-8
D/OkHttp: Content-Length: 37
D/OkHttp: {"password":"123","username":"user1"}
D/OkHttp: --> END POST (37-byte body)
D/OkHttp: <-- 404 Not Found {{url}}/user/login (949ms)
D/OkHttp: Access-Control-Allow-Origin: *
D/OkHttp: Content-Type: application/json; charset=utf-8
D/OkHttp: Date: Thu, 26 Dec 2019 22:33:50 GMT
D/OkHttp: ETag: W/"96-TmaW8mJnRKK42sZor5CoHUxYs00"
D/OkHttp: Server: nginx
D/OkHttp: Vary: Accept-Encoding
D/OkHttp: x-srv-span: v=1;s=9d533722ff5763e0
D/OkHttp: x-srv-trace: v=1;t=e07f6fb3917ed6bb
D/OkHttp: Connection: keep-alive
D/OkHttp: {"error":{"name":"mockRequestNotFoundError","header":"No matching requests","message":"Double check your method and the request path and try again."}}
D/OkHttp: <-- END HTTP (150-byte body)

This obviously isn't matching correctly somehow which is strange, I'm assuming it's the Content-Type header being application/json; charset=utf-8, so if I change this in postman in both the Example and the request it no longer matches somehow.

Has anyone experienced this recently and know a solution?

Daniel Sims
  • 531
  • 4
  • 21

0 Answers0