我正在制作一个模拟邮递员集合以在 android 应用程序中使用。我从一个简单的{{url}}/user/login
端点开始,似乎遇到了Content-Type
标题问题。Retrofit 默认将其添加为application/json; charset=UTF-8
,这很好,但问题是内容正文匹配器似乎无法匹配我的请求正文。在邮递员中这也不起作用,我的例子是 -
Successful Request
Request Headers
Content-Type - application/json
Request Body
{
"username": "user1",
"password": "123"
}
Response Body
{
"first_name" : "user",
"last_name": "one"
}
(我在x-mock-match-request-body
改造和邮递员的请求中都使用了标头)。
当我从我的应用程序发送请求时,该请求被记录为 -
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)
这显然不是以某种方式正确匹配,这很奇怪,我假设它的Content-Type
标题是application/json; charset=utf-8
,所以如果我在示例和请求中的邮递员中更改它,它不再以某种方式匹配。
最近有没有人遇到过这种情况并知道解决方案?