%Rst = handle_req(Req#cowboy_req:req.qs%http_req.qs),
{ContentType,Rst} = handle_req(element(14,Req)),
Req2 = cowboy_req:reply(200, [
% {<<"content-type">>, <<"text/plain">>}
% {<<"content-type">>, <<"text/html; charset=utf-8">>}
ContentType
]
{ContentType,Rst} = handle_req(element(14,Req)),
Req2 = cowboy_req:reply(200, [
% {<<"content-type">>, <<"text/plain">>}
% {<<"content-type">>, <<"text/html; charset=utf-8">>}
ContentType
]
,Rst,Req),
{<<"content-type">>, <<"text/plain">>} 返回的是txt
{<<"content-type">>, <<"text/html; charset=utf-8">>} 返回的是html
Rst是返回的内容;如果返回的是跳转到特定URL(比如3秒后跳转到百度),Rst如下:
<<"<html><head><meta http-equiv=\"refresh\" content=\"3;url=http://www.baidu.com\"></head></html>">>

本文介绍了一段使用Erlang处理HTTP请求并返回不同格式响应的代码示例,包括纯文本、HTML以及重定向到特定URL的方法。
1639

被折叠的 条评论
为什么被折叠?



