以下是我发起的请求内容

:method POST
:scheme https
:path /1.1/usersByMobilePhone
:authority ---
accept /
content-type application/json
accept-language zh-Hans-CN;q=1
x-lc-id ---
content-length 56
x-lc-sign ---
user-agent -/1.0.3 (iPhone; iOS 12.2; Scale/3.00)
accept-encoding br, gzip, deflate

content
{
"smsCode": "11222555",
"mobilePhoneNumber": "13668146987"
}

以下为回复的内容

:status 400
server nginx
date Tue, 07 May 2019 03:48:45 GMT
content-type application/json;charset=utf-8
cache-control no-cache,no-store
pragma no-cache
x-request-id d3f866e2b4dacc71bbae36160c2c63b4
x-request-path lb_5_225, m_850b8db_f59ffd56_23311

content

{
"code": 603,
"error": "无效的短信验证码"
}

Code 400的定义不应该是 用于告知客户端发送了一个错误的请求,一般表示请求错误了。

这种情况确实属于「客户端发送的请求是不对的」。

但是我这个statuscode确实很容易让人误会是我客户端http请求错误。然而http请求确实是成功的,服务端也接收到数据并且返回了错误的信息给我。

蔡剑雄 武汉小安科技有限公司 电话:02759765090-850 邮箱:caijianxiong@xiaoantech.com

   		 武汉小安科技有限公司  	 企业主页

信息安全声明:本邮件包含信息归发件人所在组织所有,发件人所在组织对该邮件拥有所有权利。 请接收者注意保密,未经发件人书面许可,不得向任何第三方组织和个人透露本邮件所含信息的全部或部分。以上声明仅适用于工作邮件。 Information Security Notice: The information contained in this mail is solely property of the sender's organization. This mail communication is confidential. Recipients named above are obligated to maintain secrecy and are not permitted to disclose the contents of this communication to others. ------------------------------------------------------------------ 发件人:leeyehsupport@leancloud.rocks 日 期:2019年05月07日 12:29:11 收件人:caijianxiong@xiaoantech.com 主 题:[LeanCloud 用户社区] [问题讨论/SDK / API] 调用 usersByMobilePhone ,输入非正确的手机号或者验证码为什么会回复 StatusCode 400?

 	leeyeh 自动回复机器人

May 7

这种情况确实属于「客户端发送的请求是不对的」。 通过邮件回复或者在浏览器中访问 https://forum.leancloud.cn/t/usersbymobilephone-statuscode-400/20235/2 。 之前的回复

 	jianxiongc

May 7

以下是我发起的请求内容 :method POST :scheme https :path /1.1/usersByMobilePhone :authority --- accept / content-type application/json accept-language zh-Hans-CN;q=1 x-lc-id --- content-length 56 x-lc-sign --- user-agent -/1.0.3 (iPhone; iOS 12.2; Scale/3.00) accept-encoding br, gzip, deflate content { "smsCode": "11222555", "mobilePhoneNumber": "13668146987" } 以下为回复的内容 :status 400 server nginx date Tue, 07 May 2019 03:48:45 GMT content-type application/json;charset=utf-8 cache-control no-cache,no-store pragma no-cache x-request-id d3f866e2b4dacc71bbae36160c2c63b4 x-request-path lb_5_225, m_850b8db_f59ffd56_23311 content { "code": 603, "error": "无效的短信验证码" } Code 400的定义不应该是 用于告知客户端发送了一个错误的请求,一般表示请求错误了。 通过邮件回复或者在浏览器中访问 https://forum.leancloud.cn/t/usersbymobilephone-statuscode-400/20235/2 。 如果你希望取消这些邮件的订阅,请访问你的用户设置。

HTTP status code 就是用来体现业务层状态的,4xx 表示错在客户端,仅此而已。与「http请求确实是成功的,服务端也接收到数据且返回了错误的信息给我」没有关系哦。

附件中描述的是客户端发送了一些无法处理的东西。比如格式错误请求报文。 而有一篇restful最佳实践中描述的是

400 服务器不理解客户端的请求,未做任何处理。 http://www.ruanyifeng.com/blog/2018/10/restful-api-best-practices.html1

那么问题就成为了是HTTP请求错误还是业务错误呢?

蔡剑雄 武汉小安科技有限公司 电话:02759765090-850 邮箱:caijianxiong@xiaoantech.com

   		 武汉小安科技有限公司  	 企业主页

信息安全声明:本邮件包含信息归发件人所在组织所有,发件人所在组织对该邮件拥有所有权利。 请接收者注意保密,未经发件人书面许可,不得向任何第三方组织和个人透露本邮件所含信息的全部或部分。以上声明仅适用于工作邮件。 Information Security Notice: The information contained in this mail is solely property of the sender's organization. This mail communication is confidential. Recipients named above are obligated to maintain secrecy and are not permitted to disclose the contents of this communication to others.