【问题标题】:Erlang custom httpd module - how to send custom HTTP headers and Content-TypeErlang 自定义 httpd 模块 - 如何发送自定义 HTTP 标头和 Content-Type
【发布时间】:2011-11-12 20:21:54
【问题描述】:

我正在为 Erlang 的 httpd (inets) 服务器实现一个自定义模块。我可以使用do 方法的以下实现成功地响应 HTML 内容:

do(_ModData) ->
    Body = "<html><body>Hello world</body></html>",
    {proceed, [{response, {200, Body}}]}.

但问题是我找不到使用自定义标题和text/xml 内容类型进行响应的方法。

根据 erlang httpd 文档,我可以回复 [{response,{response,Head,Body}}],其中“Head 是 HTTP 标头字段的键值列表”(引用自文档),但该列表的确切格式应该是什么?我尝试了以下方法,但它给出了 404:

do(_ModData) ->
    Body = "<html><body>Stats Placeholder</body></html>",
    Head = ["Content-Length", "40", "Content-Type", "text/html"],
    {proceed, [{response, {response, Head, Body}}]}.

对此的任何帮助将不胜感激,erlang httpd 的文档和示例真的很少......

【问题讨论】:

    标签: erlang inets


    【解决方案1】:

    试试 [{"Content-Length", "40"}, {"Content-Type", "text/html"}]

    【讨论】:

      【解决方案2】:

      试试[{content_length, "40"}, {content_type, "text/html"}]

      【讨论】:

        【解决方案3】:

        哈哈。在文档中。

        [{code, 200}, {content_length, "40"}, {content_type, "text/html"}]
        

        【讨论】:

          猜你喜欢
          • 2011-09-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-27
          • 1970-01-01
          • 1970-01-01
          • 2016-04-29
          相关资源
          最近更新 更多