rails 法拉第 API 电话问题
rails faraday for API call Issue
法拉第调用 API;
时出现未定义方法“主体”错误
URL - https://api.company.com/api/v1/dept/person/query/empid/22435678
我还需要传递用户名和密码。这就是我正在尝试的。我做错了什么?
require 'faraday'
require 'faraday/net_http'
Faraday.default_adapter = :net_http
def show
@response = Faraday.new('https://api.company.com/api/v1/dept/person/query/empid/22435678') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
end
end
您只设置了法拉第对象,并没有用它发送实际请求。
# NOTE: configure faraday
api = Faraday.new('https://api.company.com/api/v1/dept/person/query/empid/22435678') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
end
# NOTE: send requests to api `get`, `post` etc.
@response = api.get.body
这是首选设置:
api = Faraday.new('https://api.company.com/') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
# conn.response :json # automatically parse responses as json, if needed
end
@response = api.get("api/v1/dept/person/query/empid/22435678").body
法拉第调用 API;
时出现未定义方法“主体”错误URL - https://api.company.com/api/v1/dept/person/query/empid/22435678
我还需要传递用户名和密码。这就是我正在尝试的。我做错了什么?
require 'faraday'
require 'faraday/net_http'
Faraday.default_adapter = :net_http
def show
@response = Faraday.new('https://api.company.com/api/v1/dept/person/query/empid/22435678') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
end
end
您只设置了法拉第对象,并没有用它发送实际请求。
# NOTE: configure faraday
api = Faraday.new('https://api.company.com/api/v1/dept/person/query/empid/22435678') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
end
# NOTE: send requests to api `get`, `post` etc.
@response = api.get.body
这是首选设置:
api = Faraday.new('https://api.company.com/') do |conn|
conn.request :authorization, :basic, 'testuser', '77hfhncqjwnd'
# conn.response :json # automatically parse responses as json, if needed
end
@response = api.get("api/v1/dept/person/query/empid/22435678").body