Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants