1
httpd:info(Pid).
      [{mime_types,[{"html","text/html"},{"htm","text/html"}]},
      {server_name,"httpd_test"},
      {bind_address, {127,0,0,1}},
      {server_root,"/tmp"},
      {port,59408},
      {document_root,"/tmp/htdocs"}]

我在确认 httpd 信息时看到了 mime_type {"html", "text/html"}。但我想这些类型添加 application/x-www-form-urlencoded application/json application/erlang-binary

但我找不到方法。

这是 API 文档。管理属性

{mime_types, [{MimeType, Extension}] | path()}
Where MimeType = string() and Extension = string(). Files delivered to the client are MIME typed according to RFC 1590. File suffixes are mapped to MIME types before file delivery. The mapping between file suffixes and MIME types can be specified as an Apache like file as well as directly in the property list. Such a file may look like:

# MIME type Extension  
text/html   html htm
text/plain  asc txt

Defaults to [{"html","text/html"},{"htm","text/html"}]

{mime_type, string()}
When the server is asked to provide a document type which cannot be determined by the MIME Type Settings, the server will use this default type.

我该如何解决问题?

4

1 回答 1

1
-module(hello_world).
-export([start/0,service/3]).

start() ->
inets:start(httpd, [
{modules, [
mod_alias, 
mod_auth, 
mod_esi, 
mod_actions, 
mod_cgi, 
mod_dir, 
mod_get, 
mod_head, 
mod_log, 
mod_disk_log
]},
{port,8081},
{server_name,"hello_world"},
{server_root,"log"},
{document_root,"www"},
{erl_script_alias, {"/erl", [hello_world]}},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{mime_types,[
{"html","text/html"},
{"css","text/css"},
{"js","application/x-javascript"},
{"json","application/json"}
]}
]).

service(SessionID, Env, Input) ->
io:write(Env),
io:write(Input),
mod_esi:deliver(SessionID, [
"Content-Type: text/html\r\n\r\n", 
"<html><body>",
"Hello, World!</body></html>"
]).

这是示例代码

于 2013-06-12T01:09:04.220 回答