Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Phoenix中,send_resp()和put_resp_content_type()是将字符串作为XML发送的标准方式吗?_Xml_Elixir_Phoenix Framework - Fatal编程技术网

在Phoenix中,send_resp()和put_resp_content_type()是将字符串作为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

在Phoenix中,将字符串作为XML响应发送的规范方式是什么

我有下面的代码,它工作得很好,但似乎我应该使用渲染或类似的

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没有现成的东西……谢谢您的参考!