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

Cannot upload file using SSL even though I even accept invalid SSL certificates #130

Open
slashburn opened this issue May 1, 2016 · 0 comments

Comments

@slashburn
Copy link

Hi there,

I would like to add SSL support for my app. For testing purposes, I use an self generated Let's encrypt SSL certificate from my web host to protect my my URL. Now I would like to upload a file using the HTTPS instead of the HTTP protocol.

As shown in the owncloud example project (AppDelegate), I configured my OCCommunication object to accept invalid SSL certificates. I also set a the "Allow Arbitrary load flag" in my own project (not the owncloud project). The configuration looks like this :

import AFNetworking

let ocCommunication = OCCommunication()
ocCommunication.setCredentialsWithUser(userName, andPassword: password)

let securityPolicy  = AFSecurityPolicy.defaultPolicy()
securityPolicy.allowInvalidCertificates = true;
ocCommunication.securityPolicy = securityPolicy

I installed the AFNetworking 2.6. version via Cocoapods to have access to the AFNetworking library
The request looks like this:

var operation : NSOperation? = nil
operation = ocCommunication.uploadFile(folderURL.path, toDestiny: fileURL, onCommunication: ocCommunication,
            progressUpload: ({ (bytesWrote, totalBytesWrote, totalBytesExpectedToWrite) in
                //this method is not called
            }),
            successRequest: ({(response, redirectedServer) in
                // success case ...
            }),
            failureRequest: ({ (response, redirectedServer, error) in
                //this is where the error occurs
                print(response)
                print(error)
            }),
            failureBeforeRequest: ({ error in
               //not called
            }),
            shouldExecuteAsBackgroundTaskWithExpirationHandler: ({
                operation?.cancel()
            }))
operation?.start()

The output of the error message is:

<NSHTTPURLResponse: 0x130c44fb0> { URL: https:/[myURL.de]/remote.php/webdav/4690FDD4-D350-4513-9797-451A76FD7591.zip } { status code: 401, headers {
"Accept-Language" = "de-DE;q=1, en-DE;q=0.9";
Authorization = "Basic abcdefghi";
"Content-Length" = 2680387;
"User-Agent" = "MyApp/1.0 (iPhone; iOS 9.3.1; Scale/2.00)";
} }
Error Domain=com.owncloud Code=401 "(null)"

My request is somehow unauthorized. If I try to upload a file using curl with HTTPS, it works perfectly fine. I also see the green HTTPS lock when I open the site in the browser window.
Does anyone have an idea what I'm doing wrong?

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

1 participant