Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails在有效设备登录时返回401_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails Rails在有效设备登录时返回401

Ruby on rails Rails在有效设备登录时返回401,ruby-on-rails,devise,Ruby On Rails,Devise,我跟着导游走。我正在尝试使用HTTPie从服务器获得200个成功响应 http -a peter@cleanpixel.nl POST http://localhost:3000/auth/sign_in http: password for peter@cleanpixel.nl@localhost:3000: HTTP/1.1 401 Unauthorized Cache-Control: no-cache Content-Type: application/json; charset=u

我跟着导游走。我正在尝试使用HTTPie从服务器获得200个成功响应

http -a peter@cleanpixel.nl POST http://localhost:3000/auth/sign_in

http: password for peter@cleanpixel.nl@localhost:3000:
HTTP/1.1 401 Unauthorized
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Vary: Origin
X-Request-Id: 173aea74-eef6-4070-b3bb-832f39a2a7ba
X-Runtime: 0.055728

{
    "errors": [
        "Invalid login credentials. Please try again."
    ]
}
但是我已经检查了,仔细检查了,三次检查了细节。他们是正确的

这是我的user.rb:

class User < ActiveRecord::Base
  # Include default devise modules.
  devise :database_authenticatable,
         :registerable,
         :recoverable,
         :rememberable,
         :trackable,
         :validatable,
         :confirmable,
         :omniauthable
  include DeviseTokenAuth::Concerns::User
end
应用程序控制器:

class ApplicationController < ActionController::API
  include DeviseTokenAuth::Concerns::SetUserByToken
  include Response
end
class ApplicationController
我的HTTPie呼叫错误吗?我忘了在Ruby或Desive中配置一些东西了吗?我见过有人在401和Desive方面遇到麻烦,但看起来解决方案是针对旧版本的

我现在尝试了一些curl命令,但没有成功

curl-v-X“POST”http://localhost:3000/auth/sign_in“-H”内容类型:application/json;charset=utf-8“-d$”{“email”:user@example.com“,”密码“:“monkey67”}”
返回:

卷曲:(3)[globbing]第9列中不匹配的右括号/括号

如果我运行
curl-v-H'内容类型:application/json'-H'Accept:application/json'-X POSThttp://localhost:3000/auth/sign_in -d'{“电子邮件”:”user@example.com“,”密码“:“monkey67”}”
我得到:

注意:不必要地使用-X或--request,POST已经推断出来。 *无法解析主机:应用程序 *正在关闭连接0 curl:(6)无法解析主机:应用程序 注意:不必要地使用-X或--request,POST已经推断出来。 *无法解析主机:应用程序 *关闭连接1 curl:(6)无法解析主机:应用程序 注意:不必要地使用-X或--request,POST已经推断出来。 *正在尝试::1。。。 *TCP_节点集 *连接到::1端口3000失败:连接被拒绝 *正在尝试127.0.0.1。。。 *TCP_节点集 *已连接到本地主机(127.0.0.1)端口3000(#2) HTTP/1.1中的POST/auth/sign_ 主机:localhost:3000 用户代理:curl/7.54.1 接受:/ 内容长度:25 内容类型:application/x-www-form-urlencoded

  • 上传已完全发送:25个字节中有25个

我认为问题在于你的请求,你只是在传递电子邮件,你还需要添加密码。如您所说,如果您正在使用HHTPie,则需要按照中所述提供密码

你必须用类似的东西

http -a peter@cleanpixel.nl:some_password POST  http://localhost:3000/auth/sign_in

当我使用所述请求时,它确实要求输入密码。我试试看<代码>传递用户名:密码对作为参数。或者,如果您只指定一个用户名(-a username),则在发送请求之前,系统会提示您输入密码。
如果您尝试使用文章末尾提到的crul登录,会发生什么情况?curl-v-X“POST”“”\-H”内容类型:application/json;charset=utf-8“\-d$”{“email”:peter@cleanpixel.nl,“password”:“some_password”}当我尝试运行命令时,我得到错误:
Started POST”/auth/sign_-in“for 127.0.0.1 at 2017-07-03 21:27:10+0200解析请求参数时出错。内容:${email:ActionDispatch::Http::Parameters::ParseError(822:在${email:'处出现意外标记):
只要删除
$
。是的,我已经尝试过了。好消息是,当我通过浏览器检查登录时,我得到了200的响应,这很好。
http -a peter@cleanpixel.nl:some_password POST  http://localhost:3000/auth/sign_in