You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby中如何获取PUT请求返回的URL值?遇URL为null问题

问题:PUT请求返回URL为null,无法获取目标值

我需要获取PUT请求返回的URL值,但当前PUT请求返回结果为:

{"result":{"attempts":1,"url":null}}

无法定位问题所在。

操作流程

  • 先向/challenges发送POST请求启动挑战
  • 在响应的actives_at字段指定的时间,向/challenges发送PUT请求,请求头携带X-Challenge-Id(挑战ID)

实现代码

loop do
  response = HTTParty.put("#{API_ENDPOINT}/challenges", headers: { 'X-Challenge-Id' => challenge_id })
  puts "Response: #{response}"

  if response['error']
    puts "Error: #{response['error']}"
  elsif response.key?('result')
    result = response['result']
    attempts = result['attempts']
    url = result['url']
    if attempts.zero?
      puts "Challenge failed. Attempts: #{attempts}"
    elsif url.nil?
      puts "Challenge succeeded but no URL available. Attempts: #{attempts}"
    else
      puts "Challenge succeeded. Attempts: #{attempts}"
      puts "URL with keyword: #{API_ENDPOINT}#{url}"
    end

    break
  end
end

当前程序输出“Challenge succeeded but no URL available. Attempts: 1”,始终无法获取有效的URL值。


内容的提问来源于stack exchange,提问作者Wanyu Jiang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 01:05:06