gpt4 book ai didi

ruby - 使用 rest-client 获取请求的正确语法

转载 作者:数据小太阳 更新时间:2023-10-29 07:21:26 27 4
gpt4 key购买 nike

现在我可以提出如下请求:

user = 'xxx'  
token = 'xxx'
survey_id = 'xxx'
response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getLegacyResponseData&User=#{user}&Token=#{token}&Version=2.0&SurveyID=#{survey_id}&Format=XML"

但是应该有一些更好的方法来做到这一点。我试过类似的东西:

response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :Request => 'getLegacyResponseData', :User => user, :Token => token, :Version => '2.0', :SurveyID => survey_id, :Format => 'XML'</code>

及其变体(字符串而不是键的符号,包括 { 和 },使键小写等)但我尝试的组合似乎都不起作用。这里的正确语法是什么?


我尝试了下面的第一个建议。它没有用。作为记录,这有效:

surveys_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php?Request=getSurveys&User=#{user}&Token=#{token}&Version=#{version}&Format=JSON"

但这不是:

surveys_from_api = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :params => {:Request => 'getSurveys', :User => user, :Token => token, :Version => version, :Format => 'JSON'}

(我设置了 version = '2.0')。

最佳答案

您需要使用符号 :params 指定查询字符串参数。否则它们将被用作标题。

参数示例:

response = RestClient.get "https://survey.qualtrics.com/WRAPI/ControlPanel/api.php", :params => {:Request => 'getLegacyResponseData', :User => user, :Token => token, :Version => '2.0', :SurveyID => survey_id, :Format => 'XML'}

关于ruby - 使用 rest-client 获取请求的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11479478/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com