项目
在 GitHub 查看 Ruby
Alternatives to
augustl/net-http-cheat-sheet
关于
Ruby Net::HTTP 示例集合。
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Ruby Net::HTTP cheat sheet
A bunch of examples of various use cases, implemented with Ruby's Net::HTTP library.
Alternatives to Net::HTTP
This cheat sheet was created many years ago, when invoking Net::HTTP directly was common. These days, there are better alternatives around, with much nicer APIs.
Compare multipart file uploads with Net::HTTP:
BOUNDARY = "AaB03x"
uri = URI.parse("http://something.com/uploads")
file = "/path/to/your/testfile.txt"
post_body = []
post_body << "--#{BOUNDARY}\r\n"
post_body << "Content-Disposition: form-data; name=\"datafile\"; filename=\"#{File.basename(file)}\"\r\n"
post_body << "Content-Type: text/plain\r\n"
post_body << "\r\n"
post_body << File.read(file)
post_body << "\r\n--#{BOUNDARY}--\r\n"
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.body = post_body.join
request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
http.request(request)
And file uploads with RestClient - just a single line, and no shoddy manual string concatenation:
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
Check out RestClient! https://github.com/rest-client/rest-client
探索相关项目
加载中…