CherryPy 在 nsIXMLHttpRequest 上返回状态 301(但对于 firefox HTTP 请求工作正常)

发布于 2024-12-07 13:06:10 字数 706 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-12-14 13:06:11

可能是因为 /myAPI/myAPI/ 不是同一个 URI,因此它将您从一个 URI 重定向到另一个。您可以使用 http:// /docs.cherrypy.org/dev/refman/lib/cptools.html#cherrypy.lib.cptools.trailing_slash

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文