RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Ruby学习笔记系列(一)

1, 用Net::HTTP.get

主要从事网页设计、PC网站建设(电脑版网站建设)、wap网站建设(手机版网站建设)、响应式网站建设、程序开发、微网站、微信小程序开发等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了丰富的网站设计、做网站、网络营销经验,集策划、开发、设计、营销、管理等多方位专业化运作于一体,具备承接不同规模与类型的建设项目的能力。

uri = URI('http://xxxxxxx.com/api/user/1.0/json/get_info?&user_id=3')
Net::HTTP.get(uri)

2, 用Net::HTTP.get 时加一些参数

uri = URI('http://xxxxxx.com/api/user/1.0/json/get_info')
params = { :user_id => 3}
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
puts res.body if res.is_a?(Net::HTTPSuccess)

3, Net::HTTP.post_form

uri = URI('http://xxxxx.com/api/user/1.0/json/login')
res = Net::HTTP.post_form(uri, 'client_id' => '159d8a2f931514c107280', 'identity' => 'xxxxx002','password' => 'xxxxxx')
puts res.body

4, res.methods里面有些很有用的方法

uri = URI('http://drhel31.sh.magima.com/api/user/1.0/json/get_info?&user_id=3')
res = Net::HTTP.get_response(uri)
# Headers
res.header          # => "#"
res.read_header     # => "#"
# Status 这个很有用,做接口调用成功与否的判断可用。
puts res.code       # => '200'
puts res.message    # => 'OK'
puts res.class.name # => 'HTTPOK'
res.code_type       # =>  Net::HTTPOK
res.inspect         # =>  "#"
# Body
puts res.body if res.msg == "OK"

5, 判断文件是否存在

File.exist? '/home/test/features/support/modul_login.rb'


文章题目:Ruby学习笔记系列(一)
文章URL:http://sczitong.cn/article/gpgeoh.html