当内容类型为“application/json”时,Revel 不解析 JSON 参数。
如何执行?
例子 :
http://localhost:9000/foundations
在 POST 调用Foundations.Create
函数中。进入我fmt.Println("Params :", c.Params)
用来检查参数的这个函数
Ruby POST JSON 数据
#!/usr/bin/env ruby
require "rubygems"
require "json"
require "net/https"
uri = URI.parse("http://localhost:9000/foundations")
http = Net::HTTP.new(uri.host, uri.port)
header = { "Content-Type" => "application/json" }
req = Net::HTTP::Post.new(uri.path, header)
req.body = {
"data" => "mysurface"
}.to_json()
res = http.start { |http| http.request(req) }
调试打印是
Params : &{map[] map[] map[] map[] map[] map[] []}
当我不使用“应用程序/json”时:
curl -F 'data=mysurface' http://127.0.0.1:9000/foundations
打印是:
Params : &{map[data:[mysurface]] map[] map[] map[] map[data:[mysurface]] map[] []}