从 CFHTTPMessageRef 获取原始 HTTP 请求

发布于 2024-07-10 12:13:57 字数 613 浏览 4 评论 0原文

我正在使用 CFHTTPMessage 的包装类,其中包含一个 CFHTTPMessageRef 对象,其中添加了方法 (GET)、Web 应用程序服务器的 URL 和一些内容包含日期和身份验证随机数的自定义标头。

我在获取返回某些数据的方法和 URL 时遇到一些问题。 我想我已经计算出了身份验证随机数。

我想通过查看发送到 Web 应用程序的原始请求并确保所有内容的格式正确来解决此问题。

我的问题是:如果我有一个 CFHTTPMessageRef 对象(例如 messageRef),有没有办法记录来自此消息的原始 HTTP 请求?

我已尝试以下操作,但当我尝试访问其字节时收到 EXC_BAD_ACCESS 信号:

CFDataRef messageData = CFHTTPMessageCopyBody(messageRef);

感谢您的任何建议。

作为替代方案,是否可以在交换网络上使用数据包嗅探器? 我可以在笔记本电脑设备上运行 ettercap,但不知道如何嗅探我的 iPhone 在本地无线网络上正在执行的操作。

I am working with a wrapper class for CFHTTPMessage, which contains a CFHTTPMessageRef object to which is added the method (GET), the URL of the web application server, and a few custom headers containing the date and an authentication nonce.

I'm having some problems getting the method and URL to return certain data. I think I've worked out the authentication nonce.

I'd like to troubleshoot this by looking at the raw request going to the web application, and making sure everything is formatted properly.

My question is: If I have a CFHTTPMessageRef object (e.g. messageRef), is there a way to log the raw HTTP request that comes out of this message?

I've tried the following but I get a EXC_BAD_ACCESS signal when I try to access its bytes:

CFDataRef messageData = CFHTTPMessageCopyBody(messageRef);

Thanks for any advice.

As an alternative, is it possible to use a packet sniffer on a switched network? I can run ettercap on a laptop device, but don't know how to sniff what my iPhone is doing on the local wireless network.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

莫多说 2024-07-17 12:13:57

以下效果很好:

NSData *d = (NSData *)CFHTTPMessageCopySerializedMessage(messageRef);
NSLog(@"%@",[[[NSString alloc] initWithBytes:[d bytes] length:[d length] encoding:NSUTF8StringEncoding] autorelease]);

希望这对其他人有帮助。

The following worked well:

NSData *d = (NSData *)CFHTTPMessageCopySerializedMessage(messageRef);
NSLog(@"%@",[[[NSString alloc] initWithBytes:[d bytes] length:[d length] encoding:NSUTF8StringEncoding] autorelease]);

Hope this is helpful to others.

独夜无伴 2024-07-17 12:13:57

访问字节时应该得到 EXC_BAD_ACCESS 的唯一原因是 messageData 为 NULL(无 HTTP 正文)并且您取消引用它。

要记住的一点是:HTTP 正文不是“原始请求”。 它不包括标头或实际的 HTTP 指令 (GET/POST/ETC)。 如果您没有实际设置正文内容,则它将为零。

您的 CFHTTPMessageRef 值可能未正确初始化(但可能性较小)。 在调试器中检查这一点,方法是在 CFHTTPMessageCopyBody 行上设置断点,转到调试器控制台窗口,将文本输入光标设置到该窗口的最后一行,然后键入“po messageRef”。 如果有效初始化,它应该给您一条 CFTypeID 消息。

The only reason why you should be getting an EXC_BAD_ACCESS when accessing the bytes is if the messageData is NULL (no HTTP body) and you're dereferencing it.

Point to remember: the HTTP body isn't the "raw request". It doesn't include the headers or the actual HTTP instruction (GET/POST/ETC). If you haven't actually set body content, it will be nil.

It is possible (but less likely) that your CFHTTPMessageRef value isn't properly initialized. Check this in the debugger by setting a breakpoint on your CFHTTPMessageCopyBody line, going to the Debugger Console window, setting the text input cursor to the last line in this window and typing "po messageRef". It should give you a CFTypeID message if validly initialized.

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