I am developing a web API in using CherryPy. The intent is that it is accessed by JavaScript through nslXMLHttpRequest. When I access the API through Firefox (as though it were an ordinary-variety URL), the following appears in my logs:
我正在使用CherryPy开发一个web API。其目的是让JavaScript通过nslXMLHttpRequest访问它。当我通过Firefox访问API(好像它是一个普通的URL)时,我的日志中会出现以下内容:
!!!SUCCESS!!!
[my IP] - - [30/Sep/2011:08:30:19] "GET /myAPI/ HTTP/1.1" 200 11 "" "Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"
That "!!!SUCCESS!!!" is printed at the start of the code that runs on the myAPI page. But when I access it through JavaScript, the following appears in my logs:
在myAPI页面上运行的代码的开始处打印“!!! !!”。但是当我通过JavaScript访问它时,我的日志中出现了如下内容:
[my IP] - - [30/Sep/2011:08:32:19] "GET /myAPI?arg1=value1&arg2=value2 HTTP/1.1" 301 221 "[requesting page]" "Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2"
(those arguments are optional)
(这些参数是可选的)
Notice that in the second case, !!!SUCCESS!!! was never printed (my code was never executed) and the status code was 301 - "moved permanently". Any idea what would cause CherryPy to do this?
注意在第二种情况下,成功!从来没有打印过(我的代码从未被执行过),而状态代码是301——“永久移动”。你知道什么会让CherryPy这么做吗?
1 个解决方案
#1
3
Probably because /myAPI
and /myAPI/
are not the same URI, so it's redirecting you from one to the other. You can fine-tune this behavior with http://docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slash
可能是因为/myAPI和/myAPI/不是相同的URI,所以它将您从一个URI重定向到另一个。您可以使用http://docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slash来微调这种行为
#1
3
Probably because /myAPI
and /myAPI/
are not the same URI, so it's redirecting you from one to the other. You can fine-tune this behavior with http://docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slash
可能是因为/myAPI和/myAPI/不是相同的URI,所以它将您从一个URI重定向到另一个。您可以使用http://docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slash来微调这种行为