【问题标题】:How do I extract the response code from a JSON API request?如何从 JSON API 请求中提取响应代码?
【发布时间】:2012-02-09 23:05:19
【问题描述】:

这样做:

@resp = Net::HTTP.get_response("api.something.com", "/feed/v1/offers.json?#{@params_api_string}")

我在@resp 中收到此回复:

#<Net::HTTPOK:0x7f451e9d3ef0> 

如何在一个变量中提取 OK、No Content、Bad Request、Unathorized 等等?是否有一些 Net::HTTP 函数来获取这些信息?

【问题讨论】:

    标签: ruby json http


    【解决方案1】:
    @resp.message
    

    应该给你消息。

    the documentation 中提供了更多 HTTPResponse 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-16
      • 2019-02-25
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      相关资源
      最近更新 更多