http - 我如何从该 URL 获取值?并使用值执行 erlang 模块以向客户端回复结果?

标签 http erlang yaws erlangweb

http://www.myserver.com/exile?Key1=Value1&Key2=Value2

当我的服务器收到这种格式的请求时, 我该如何处理这个请求? 我需要做什么:需要获取所有值并运行 Erlang 模块,并将结果发送到客户端。是否放逐 CGI,如果是,为什么它没有 .cgi 扩展名?

附加数据: 我在我的服务器上设置了 Yaws(运行 Linux 服务器的桌面)。 yaws.conf 文件已配置。

最佳答案

解决办法如下:

<erl>

out(A)->
    Values = yaws_api:parse_query(A),
    Value1 = proplists:get_value("Key1",Values),
    Value2 = proplists:get_value("Key2",Values),
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

更多信息请参见: http://yaws.hyber.org/query.yaws

<erl>

out(A)->
    Value1 = yaws_api:queryvar(A,"Key1"),
    Value2 = yaws_api:queryvar(A,"Key2"),
    %% Need to be careful here
    %% if the value aint found, the 
    %% variable will contain an atom 'undefined'
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

或者

<erl>

out(A)->
    Value1 = yaws_api:getvar(A,"Key1"),
    Value2 = yaws_api:getvar(A,"Key2"),
    %% Need to be careful here
    %% if the value aint found, the 
    %% variable will contain an atom 'undefined'
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

了解有关模块的更多信息: yaws_api.erl

*注意*避免使用最后一个选项 (getvar/2),因为它首先检查 POST 数据,然后还检查 GET 数据,查找对于您指定的参数。仅当您不确定参数是来自 GET 还是 POST 请求数据时才应使用它。

关于http - 我如何从该 URL 获取值?并使用值执行 erlang 模块以向客户端回复结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8720656/

相关文章:

ssl - 即使通过不安全的选项,使用 hackney 发出请求时证书未知

bootstrap-4 - 使用 Erlang Nitrogen 和 Bootstrap 4 模板

mysql - 我如何使用 Erlang 的 Yaws Web 服务器访问 MySQL

erlang - 如何使用 Yaws 在 appmod 中处理 WebSocket 消息?

asp.net - 如何在我的 .NET Framework 4.5 应用程序/站点中使用 HttpClient?

java - 在 DNS 重定向错误的情况下,发送的正确 HTTP 响应是什么?

javascript - 从 express.js 中删除所有 header

api - 如何使用 Unfuddle API 获取文件?

erlang - 为 erlang 寻找持久的、分布式的工作队列

concurrency - 如何发送消息以在 YAWS/Erlang 中接收