`

ruby调用REST方式API测试方法

    博客分类:
  • RUBY
 
阅读更多
require 'httparty'
require 'json'
response = HTTParty.post(url,
                 {
                  :body => http_body.to_json,
                  :headers =>{"Content-Type"=>"application/json",
                  :debug_output=> $stderr
                 })
 
     def http_body
          result={}
          result["a"]="A"
          result["b"]="B"
          return result
      end
 
其中 :debug_output=> $stderr为打印post请求内容。

 
也可以用另外一种方式用curl命令快速调试api接口。
curl -H "Content-Type: application/json"  -d "{\"a\":\"A\",\"b\":\"B\"}" “your api url” -X POST 
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics