在Phoenix中,send_resp()和put_resp_content_type()是将字符串作为XML发送的标准方式吗?
在Phoenix中,将字符串作为XML响应发送的规范方式是什么 我有下面的代码,它工作得很好,但似乎我应该使用渲染或类似的在Phoenix中,send_resp()和put_resp_content_type()是将字符串作为XML发送的标准方式吗?,xml,elixir,phoenix-framework,Xml,Elixir,Phoenix Framework,在Phoenix中,将字符串作为XML响应发送的规范方式是什么 我有下面的代码,它工作得很好,但似乎我应该使用渲染或类似的 conn |> put_resp_content_type("text/xml") |> send_resp(200, some_string_with_xml) 有没有更好或更规范的方法来做到这一点 在Phoenix中,没有直接支持xml,因此您需要回到公开的内容。正如您在hello world示例中所看到的,这是一种经典的方式 defmodule MyPl
conn
|> put_resp_content_type("text/xml")
|> send_resp(200, some_string_with_xml)
有没有更好或更规范的方法来做到这一点 在Phoenix中,没有直接支持xml,因此您需要回到公开的内容。正如您在hello world示例中所看到的,这是一种经典的方式
defmodule MyPlug do
import Plug.Conn
def init(options) do
# initialize options
options
end
def call(conn, _opts) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello world")
end
end
我认为没有比这更“地道”的方法了。有一个帮助程序可以对JSON(Phoenix.Controller.JSON/2)执行类似的操作,但是如果你看一下它,它实际上是在做你在那里做的事情。就我所知,XML没有现成的东西……谢谢您的参考!