我需要debugging通过HTTP发送XML回复的XML-RPC应用程序。 我有一个示例XML回复(即从服务器的数据,发送到客户端不工作),我想debugging我的应用程序。 理想情况下,我想要一个简单的HTTP服务器,将服务于一个文件来回复所有请求。 有人要求/ ? 发送他们这个文件。 有人发一个post到/server/page.php与一个特定的cookie? 只要发送他们这个文件。 我不关心multithreading或安全性。 我只需要用几个小时来debugging。 我在机器上有根。
即我希望有这样容易使用的东西:
simple_http_server -p 12445 -f my_test_file
我知道python的SimpleHTTPServer模块,但我不知道如何使它在这种情况下工作。
如果你安装了inetd , 只需要创build一个脚本 (我犯了一个错误,脚本不需要)
#!/斌/庆典 猫$ 1
然后将该行添加到inetd.conf
http stream tcp nowait root /bin/cat cat /some/other/dir/file.txt
使用Python只需扩展BaseHTTPServer.BaseHTTPRequestHandler类并定义一个do_GET方法,然后按文档中所述运行,例如
import BaseHTTPServer class HTTPHandlerOne(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): self.wfile.write("test\r\n") def run(server_class=BaseHTTPServer.HTTPServer, handler_class=BaseHTTPServer.BaseHTTPRequestHandler): server_address = ('', 8000) httpd = server_class(server_address, handler_class) httpd.serve_forever() run(handler_class=HTTPHandlerOne)
你可以添加一个mod_rewrite规则到apache虚拟主机,将所有请求重新写回你想要服务的文件。
<VirtualHost *:80> ServerName onefilevhost.local RewriteEngine On RewriteRule ^/(.*)? http://onefilevhost.local/serve/this/file.txt </VirtualHost>
你可以用Sinatra做到这一点很容易。 安装sinatra安装gem install sinatra并创build一个test_page.rb文件,如下所示:
require 'sinatra' get '/*' do File.read('/server/page.php') end
如果你的shell没有$RUBYOPT=rubygems ,在开始处添加$RUBYOPT=rubygems require 'rubygems' 。
你可以用ruby test_page.rb运行它。 它会默认监听端口4567。