Retrieving a raw HTTP request from CFHTTPMessageRef

I am working with a wrapper class for CFHTTPMessage that contains a CFHTTPMessageRef object to which a (GET) method has been added, a web application server URL and some custom headers containing nonce date and authentication.

I'm having trouble getting the method and url to return certain data. I think I developed nonce authentication.

I would like to fix this by looking at the raw request sent to the web application and making sure everything is formatted correctly.

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

I tried the following, but I get an EXC_BAD_ACCESS signal when I try to access its bytes:

 CFDataRef messageData = CFHTTPMessageCopyBody(messageRef); 

Thanks for any advice.

As an alternative, can I use packet sniffer in a switched network? I can run ettercap on a laptop, but don’t know how to sniff what my iPhone does on a local wireless network.

+4
source share
2 answers

It worked well:

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

Hope this helps others.

+9
source

The only reason you should get EXC_BAD_ACCESS when accessing bytes is because messageData is NULL (without an HTTP body) and you are looking for it.

Point to remember: HTTP body is not a "raw request". It does not include headers or the actual HTTP statement (GET / POST / ETC). If you have not actually set the body content, it will be zero.

It is possible (but less likely) that the CFHTTPMessageRef value will not be correctly initialized. Check this in the debugger by setting a breakpoint on your line CFHTTPMessageCopyBody, going to the debugger console window, setting the text input cursor to the last line in this window and typing "po messageRef". It should provide you with the CFTypeID message if it is actually initialized.

0
source

All Articles