ruby-on-rails 如何在Rails项目中向Trello API发出PUT请求?

u91tlkcl  于 11个月前  发布在  Ruby
关注(0)|答案(1)|浏览(119)

下面的代码不工作,因为whished(即卡没有移动到所需的列ID)由于错误。

require 'net/http'

    http = Net::HTTP.new('api.trello.com')
    response = http.send_request('PUT', '/1/cards/xxxxxxcardidherexxxxxx?key=xxxxxxkeyherexxxxxx&token=xxxxxxtokenherexxxxxx&idList=xxxxxxtargettedlistidherexxxxxx')

字符串
收到错误:

=> #<Net::HTTPMovedPermanently 301 Moved Permanently readbody=true>


你知道我该怎么做吗?

guykilcj

guykilcj1#

301 Moved Permanently状态告诉您资源已移动到另一个URL。该URL可以在响应中的位置标头中找到。我向您提供的端点发出了请求,并得到了以下结果:

HTTP/1.1 301 Moved Permanently
< location: https://api.trello.com/1/actions/id?key=APIKey&token=APIToken
< date: Mon, 30 Oct 2023 07:55:53 GMT
< server: envoy
< content-length: 0

字符串
在这里,您可以看到主机不是api.trello.com,而是https://api.trello.com
因此,请不要使用http = Net::HTTP.new('api.trello.com'),请使用Net::HTTP,并为SSL连接提供额外的步骤,或者使用另一个不像Net::HTTP那么低级的请求库,例如HTTParty

相关问题