我想阅读进入Rails控制器的请求标题...
如何读取请求的标题,以查看请求期望/想要的内容(格式方面)并以该格式发回数据?
示例:
#in the controller receiving the request
def receive_req
request.head #read value from header
#if req wants json, format to json else, format to html etc...
res = response
res.head = "set appropriate header values"
res.body = "data to send back in the body"
end
#in the controller making the req
def send_request
Net::HTTP.post("/receive_req", "data", header_values)
render #{response.body}
end