凤凰城的Rails中的"head:ok"是什么意思? [英] What is the equivalent of 'head :ok' from Rails in Phoenix?

查看:92
本文介绍了凤凰城的Rails中的"head:ok"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回一个没有内容(仅标头)的响应,例如此内容

I want to return a response that has no content (merely headers) like this one

def show
  head :ok
end

推荐答案

您可以使用 Plug.Conn. send_resp/3 带有空主体:

You can use Plug.Conn.send_resp/3 with empty body:

# 200 OK
send_resp(conn, 200, "")
send_resp(conn, :ok, "") # same as above
# 401 Unauthorized
send_resp(conn, 401, "")
send_resp(conn, :unauthorized, "") # same as above

send_resp可以将状态(第二个参数)作为整数或此处提到的受支持原子之一:https://hexdocs.pm/plug/Plug.Conn.Status.html#code/1 .

send_resp can take the status (second argument) as an integer or one of the supported atoms mentioned here: https://hexdocs.pm/plug/Plug.Conn.Status.html#code/1.

这篇关于凤凰城的Rails中的"head:ok"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆