|| 操作员未按预期工作

What is going wrong here? I am 100% sure I am sending a HTTP POST request, but somehow the OR operator is not working as I am expecting. In the first example the server returns a 405 and in the second example the code continues executing.

not working:

if req.Method != http.MethodPost || req.Method != http.MethodDelete {
    http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
    return
}

working:

if req.Method != http.MethodPost {
    http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
    return
}
查看全部
dongzhihong3940
dongzhihong3940
2017/03/10 19:50
  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复