尝试在请求中添加标题
email = "blahblah@gmail.com"
token = "abcdefghijk"
url = "http://www.somewebsite.com/request?params1=value1¶ms2=value2"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port).start
request = Net::HTTP::Get.new(uri.request_uri)
request['email'] = email
request['token'] = token
response = http.request(request)
render json: response.body
我得到的结果是{"error":"invalid request parameters"}
我应该在json中找回数据列表。我尝试使用邮递员测试网址是否正常工作,并在标题内传递了电子邮件和令牌,然后我找回了我想要的数据。 我不确定代码出了什么问题。任何人都可以告诉我哪个部分做错了吗?非常感谢!
答案 0 :(得分:1)
试试这个。
for
OR
email = "blahblah@gmail.com"
token = "abcdefghijk"
url = "http://www.somewebsite.com/request?params1=value1¶ms2=value2"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port).start
request = Net::HTTP::Get.new(uri.request_uri, {'email'=>email,'token'=>token})
response = http.request(request)
render json: response.body