Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh
嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp;
你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp;
lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; vipcalio_30ef 在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z329...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; z329224946 你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; vipcalio_30ef 可以在服务端替换一下: ngx.req.read_body() local raw_data = ngx.req.get_body_data() local data = "" "\\r\\n", "\n") local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()On 2013-6-25, at 上午9:43, 朱茂海 <z329...@gmail.com> wrote:你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp; z329224946 多谢!在 2013年6月25日星期二UTC+8上午9时58分10秒,Calio写道:可以在服务端替换一下: ngx.req.read_body() local raw_data = ngx.req.get_body_data() local data = "" "\\r\\n", "\n") local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()On 2013-6-25, at 上午9:43, 朱茂海 <z3292...@gmail.com> wrote:你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp;
现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp;
lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp;
在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; vipcalio_30ef 可以在服务端替换一下: ngx.req.read_body() local raw_data = ngx.req.get_body_data() local data = "" "\\r\\n", "\n") local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()On 2013-6-25, at 上午9:43, 朱茂海 <z329...@gmail.com> wrote:你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp; z329224946 多谢!在 2013年6月25日星期二UTC+8上午9时58分10秒,Calio写道:可以在服务端替换一下: ngx.req.read_body() local raw_data = ngx.req.get_body_data() local data = "" "\\r\\n", "\n") local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()On 2013-6-25, at 上午9:43, 朱茂海 <z3292...@gmail.com> wrote:你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp;
你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp;
在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp;
可以在服务端替换一下: ngx.req.read_body() local raw_data = ngx.req.get_body_data() local data = "" "\\r\\n", "\n") local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()On 2013-6-25, at 上午9:43, 朱茂海 <z3292...@gmail.com> wrote:你好,能给个例子,如何在客户端或者在服务端进行转换吗在 2013年6月25日星期二UTC+8上午9时37分06秒,Calio写道:在Lua中获取到的body(ngx.req.get_body_data)是收到的原始数据,如果你需要把原始数据中的"\r\n"变成实际的换行,需要你自己转换一下。或者在发起Post请求的客户端中做转换。不论"\r\n",还是"\\r\\n",如果Post请求客户端并没有将其转义,那么Lua收到的也是"\r\n"或"\\r\\n"的字面值,Lua没有义务把所有请求body中的"\r\n"字面值转换成换行符。On 2013-6-25, at 上午9:31, 朱茂海 <z3292...@gmail.com> wrote:现在从客户端直接post数据到接口/save ,里面包含\r\n 或者\\r\\n,但是lua不会把这些字符解析成换行。在 2013年6月25日星期二UTC+8上午9时29分26秒,朱茂海写道:lua文件:local method = ngx.req.get_method()if ( method == "POST" ) then ngx.req.read_body() local data = ""> local file = io.open("/tmp/file","a+") file:write(data) file:flush() file:close()else local file = io.open("/tmp/file","r") data = ""> ngx.print(data) ngx.exit(200)endnginx.conf:worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { lua_code_cache off; listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /save { default_type text/html; content_by_lua_file "conf/save.lua"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}多谢啦在 2013年6月25日星期二UTC+8上午9时22分49秒,Calio写道:你能提供一下完整的测试代码,包括nginx配置和你的lua文件,还有复现问题的方法?问题描述有些模糊。On 2013-6-25, at 上午9:20, 朱茂海 <z3292...@gmail.com> wrote:嗯,尝试post \\r\\n,lua还是直接把这个字符写入到了文件,而不解析成换行在 2013年6月25日星期二UTC+8上午1时02分26秒,agentzh写道:Hello! 2013/6/23 朱茂海: > > 各位好,data是post过来接收到的数据,里面会包括\r\n的换行符,但是查看文件时,发现没有解析这个换行符,而是直接显示为\r\n,如果直接file:write("123\r\n456")就可以换行 ngx_lua 和 Lua 的 io 库都不会自作聪明地把 \r\n 转换为 \\r\\n. 请确认你的客户端是否发送的原始数据里就已经是 \\r\\n. Best regards, -agentzh -- sp; -- sp; -- sp;