Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

print httpbody as a string? #94

Open
tamoyal opened this issue Nov 15, 2017 · 1 comment
Open

print httpbody as a string? #94

tamoyal opened this issue Nov 15, 2017 · 1 comment

Comments

@tamoyal
Copy link

tamoyal commented Nov 15, 2017

I'm trying to upload a file using Just but getting a 500 from my server which I want to debug. I'm able to see the status code and the request headers but not the http body. The description of the body shows there is content (from the debugger):

(lldb) po String(r.request!.httpBody!)
"3174935 bytes"

but the actual content won't print:

(lldb) po NSString(data: r.request!.httpBody!, encoding: String.Encoding.utf8.rawValue)
nil

Any thoughts on how to look at this? I'm basically trying to make sure the body is properly formed and the source code looks fine.

My code looks like this:

Just.post("...", files: [fileName: HTTPFile.url(localFileUrl, "image/png")]) { r in
    if r.ok {
        print(r.json)
    } else {
        print(r.statusCode)
        print(r.request?.httpBody)
    }
}

where the localFileUrl is:

file:///var/mobile/Containers/Data/Application/7185716F-904E-4404-9BBD-F09EDCD4B5DD/Documents/2963391223.png
@robjtede
Copy link

robjtede commented Jan 12, 2018

if let data = r.request?.httpBody {
    print(NSString(data: data, encoding: String.Encoding.utf8.rawValue))
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants