Last active
January 4, 2017 08:51
-
-
Save beepony/0c5658930703fab938b446649c9eb9ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby -w | |
# 使用 net/http 发送 post 请求,带上自定义的 header | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
uri = URI.parse("http://xxx.com/foo/bar") | |
# 设置请求头 | |
headers = { | |
:Authorization => "UPYUN bin:#{signature(params)}", | |
:Date => "#{gmdate}", | |
:User_Agent => "beepony" | |
} | |
# 设置 post 参数,post 把参数放到 request body 里发送 | |
params = { | |
app_name: "compress", | |
bucket_name: "binimg", | |
notify_url: "http://xs.com/notify", | |
tasks: "#{tasks(zip)}" | |
} | |
# 初始化一个 http 对象 | |
http = Net::HTTP.new(uri.host, uri.port) | |
# 使用 http 对象的 post 方法 | |
response = http.post(uri.path, params.to_json, headers) | |
# 输出相应代码和响应体 | |
puts response.code,response.body | |
response.each_header {|k,v| p "#{k}":"#{v}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment