【问题标题】:Net HTTP Get request with content type, basic auth and params (https)带有内容类型、基本身份验证和参数 (https) 的 Net HTTP Get 请求
【发布时间】:2019-10-26 11:53:58
【问题描述】:

我是 NET HTTP 和 Ruby on Rails 的新手,我想使用一些 Get Request 从网站获取一些数据。网上没有太多关于这个话题的帮助。如果有人引导我朝着正确的方向前进,是否有可能。

其他信息:

我呼叫的网站:https://exampledomain.com/getinfo

使用基本身份验证

要求内容类型为 application/Jason

有 2 个参数: 页 页面大小

如果有人可以向我指出一些文档或更好的解决方案,那就太好了

我搜索了大多数网站,只发现使用基本身份验证获取请求和使用参数获取请求,但从未一起使用

【问题讨论】:

    标签: ruby-on-rails https httprequest net-http get-request


    【解决方案1】:
     uri = URI('https://exampledomain.com/getinfo/')
     http = Net::HTTP.new(uri.host, uri.port)
     http.use_ssl = true
     request = Net::HTTP::Get.new(uri.path, 'Content Type' => 'application/json')
     request.basic_auth('username', 'pass')
     resp = http.request(request)
     resp.body'    
    

    【讨论】:

      猜你喜欢
      • 2019-05-05
      • 2020-08-25
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多