Convenient way to print raw HTTP request in Swift or Objective-C?
<p>Is there a convenient way to view or print a <code>NSMutableURLRequest</code> as a raw HTTP request -- i.e. how it gets sent over the wire? Perhaps when the request is actually made? I'm specifically <strong>not</strong> trying to extract specific components of the request and manually compose them together. FWIW I'm loading it in a webview with <code>WKWebView.loadRequest(r)</code>.</p>

<p>By raw request, I mean as it is sent over the wire -- something like:</p>

<pre><code>POST /target/command HTTP/1.0
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508
Content-Type: application/json
Content-Length: 38914
Custom-Header: custom-value

{"param": "value"}
</code></pre>

<p>The reason I'm asking is because my server seems to receive an empty request body for a particular request, while it receives request bodies on others. Would be very useful if I could debug this like I debug on my server -- by printing the raw request. I understand I could use proxy tools like Charles, but I'm hoping there's a more convenient answer.</p>