Type when accessing Domino Access Service via Alamofire in Swift

I having some trouble accessing the REST API from Domino Access Service (9.0.1) via Alamofire in swift. My code looks like:

    Alamofire.request(.GET, dbPath)
        .authenticate(usingCredential: credential)
        .responseViewCollectionArray { (request, response, viewWrapper, error) in
            println("res: (response)")
            if let anError = error {
                println("error (anError)")
                completionHandler(nil, anError)
                return
            }
            println("success atPath")
            completionHandler(viewWrapper, nil)
    }

What brings me as result:

res: Optional( { URL: http://das.name.de/DASLib.nsf/api/data/collections } { status code: 404, headers { "Cache-Control" = "no-cache"; Connection = close; "Content-Length" = 220; "Content-Type" = " text/html; charset=US-ASCII "; Date = "Mon, 06 Apr 2015 06:41:37 GMT"; Expires = "Tue, 01 Jan 1980 06:00:00 GMT"; Server = "Lotus-Domino"; } }) error Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn't be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fc911f01af0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

So the content-type is wrong why I got an error when putting it into a JSON (swiftyJSON). I can see the "wrong" result using responseString instead of responseJSON from Alamofire. The strange part now is. When I am putting the end point in a rest client like CocoaRestClient it gives me a different content-type

HTTP 200 No Error

Content-Encoding: gzip Content-Length: 489 Vary: Accept-Encoding Content-Type: application/json Server: Lotus-Domino Date: Sun, 05 Apr 2015 19:41:28 GMT

If I am accessing a different part off the Domino-REST-API (eg the Databases on the Server) with the same code (only changing the end point). The code works well and I got the JSON.

So what am I missing? Maybe someone had the same problem when using REST via xPages in Domino.


As @muenzpraeger pointed out: you have a 404 - not found. Presuming that the resource does actually exist, it points to a configuration error. Most likely you haven't enabled the database or the view for access via DAS. I would be super-mega careful with DAS, once you allow WRITE access anybody who can reach the URL and has author or better access, can write back arbitrary documents and mess up your database (no validation!).

I'm working on some alternative (that also would return JSON on 404). Stay tuned

链接地址: http://www.djcxy.com/p/48184.html

上一篇: API不同的内容

下一篇: 在Swift中通过Alamofire访问Domino Access Service时键入