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/