CherryPy 在 nsIXMLHttpRequest 上返回状态 301(但对于 firefox HTTP 请求工作正常)
我正在使用 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"
内容:“!!!SUCCESS!!!”打印在 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"
这些参数是可选的)
请注意,在第二种情况下,!!!SUCCESS!!!从未打印(我的代码从未执行),状态代码为 301 - “永久移动”。知道什么会导致 CherryPy 这样做吗?
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:
!!!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:
[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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能是因为
/myAPI
和/myAPI/
不是同一个 URI,因此它将您从一个 URI 重定向到另一个。您可以使用 http:// /docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slashProbably 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