如何在 Safari 4 中调试 XHR POST 请求? [英] How to debug XHR POST requests in Safari 4?

查看:75
本文介绍了如何在 Safari 4 中调试 XHR POST 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XHR 请求在 FF3.5 中成功,但在 Safari 4 中完成时显然失败.我正在 Safari 中的调试器中查看 xhr 请求,在 Firefox 中查看 Firebug.

I've got an XHR request that's succeeding in FF3.5 but apparently failing when done in Safari 4. I'm looking at the xhr requests in the debugger in Safari, and Firebug in Firefox.

因此,在被命中的后端服务上,如果 POST 参数中缺少用户名和密码,则该服务会给出 500 错误.如果参数在那里(即使不正确),它会根据错误给出 200 或 40x.

So on the backend service that's being hit, if the username and password are missing from the POST parameter then the service gives a 500 error. If the parameters are there(even if incorrect), it gives 200 or 40x depending on the error.

无论如何,使用相同的代码可用于非 Safari 浏览器.Safari 收到 500 错误,就像用户/密码没有通过一样.

Anyway, so with the same code its working for the non-Safari browsers. Safari gets the 500 error like the user/pass aren't being passed through.

当我在调试器中检查请求时,它看起来不像在日志中显示 POST 数据.

As I'm examining the requests in the debugger, it doesn't look like it shows POST data in the logs.

是否需要启用某个选项,或者您如何在 Safari 4 中调试这些请求?

Is there an option I need to enable, or just how do you debug these requests in Safari 4?

推荐答案

如果您指的是 SafariWeb Inspector":当使用 Ajax 发送时,它确实不显示 POST 数据.我会使用像 Wireshark 这样的数据包嗅探器(但只是因为我也将它用于其他用途),或者调试代理.

If you are referring to the Safari "Web Inspector": it indeed does not show the POST data when sent using Ajax. I'd use a packet sniffer like Wireshark (but just because I also use it for other things), or a debugging proxy.

需要检查 POST 的一些事项:您是否调用 setRequestHeader 来设置所需的 HTTP 标头,例如 ConnectionContent-Type内容长度?由于您的代码适用于 Firefox,我假设您实际上是在使用 send 设置 POST 内容?请在 JS Bin 中发布您的代码!

Some things to check with your POST: are you invoking setRequestHeader to set the required HTTP headers, like Connection, Content-Type and Content-Length? And as your code works with Firefox, I assume you are actually setting the POST content using send? Post your code in JS Bin please!

(仅用于存档:除了通过 defaults.write 启用 debug 菜单外,Safari 4 还有一个 Develop 菜单,您可以可以简单地通过高级首选项启用.选择显示 Web Inspector ⌥⌘I",您应该能够在资源"选项卡上看到请求和响应.确保选择按开始时间排序".如果 XHR 是通过 GET 发送的, 显然必须查看请求 URL 本身,它显示得很好.但是,对于 POST,显示了请求标头,但遗憾的是缺少 POST 数据.我从未使用过 debug菜单.)

(Just for the archives: apart from enabling the debug menu through defaults.write, Safari 4 also has a Develop menu that you can simply enable through the advanced preferences. Choose "Show Web Inspector ⌥⌘I" and you should be able to see the requests and responses on the Resources tab. Ensure to select "Sort by Start Time". If the XHR is sent through GET, one obviously has to look at the request URL itself, which is shown fine. However, for POST, the request headers are shown, but the POST data is sadly missing. I've never used the debug menu though.)

这篇关于如何在 Safari 4 中调试 XHR POST 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆