【问题标题】:NSURLErrorDomain error codes descriptionNSURLErrorDomain 错误代码说明
【发布时间】:2012-06-17 05:32:10
【问题描述】:

这是我开发 ios 应用程序的第一次体验。我正在尝试使用 Facebook graph api 发布一些数据。我经常收到以下错误:

The operation couldn’t be completed. (NSURLErrorDomain error 400.)

我无法找到 NSURLErrorDomain 错误代码的描述。 400错误码是什么意思?

【问题讨论】:

    标签: ios nsurlerrordomain


    【解决方案1】:

    NSURLErrorDomain 错误代码在此处列出https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes

    但是,400 只是返回的 http 状态代码 (http://www.w3.org/Protocols/HTTP/HTRESP.html),这意味着您的请求有问题。

    【讨论】:

    • 希望我能多次对此表示赞同。 Google + Apple 找不到错误代码 - 当我从 Apple 得到一个难以理解的负数时,在每个新项目(而不是错误名称)上,我总是会回到这个 SO 答案以找到 Apple 文档页面!
    • @Adam 确保在 Google 中搜索负数时将其括在引号中。否则,破折号将被解释为 NOT 搜索运算符(即 exclude 此搜索词)。
    【解决方案2】:

    在 Swift 中开发时,我无法找到给定代码的错误名称。出于这个原因,我粘贴了NSURLErrorDomain 的减号代码,取自NSURLError.h

    /*!
        @enum NSURL-related Error Codes
        @abstract Constants used by NSError to indicate errors in the NSURL domain
    */
    NS_ENUM(NSInteger)
    {
        NSURLErrorUnknown =             -1,
        NSURLErrorCancelled =           -999,
        NSURLErrorBadURL =              -1000,
        NSURLErrorTimedOut =            -1001,
        NSURLErrorUnsupportedURL =          -1002,
        NSURLErrorCannotFindHost =          -1003,
        NSURLErrorCannotConnectToHost =         -1004,
        NSURLErrorNetworkConnectionLost =       -1005,
        NSURLErrorDNSLookupFailed =         -1006,
        NSURLErrorHTTPTooManyRedirects =        -1007,
        NSURLErrorResourceUnavailable =         -1008,
        NSURLErrorNotConnectedToInternet =      -1009,
        NSURLErrorRedirectToNonExistentLocation =   -1010,
        NSURLErrorBadServerResponse =       -1011,
        NSURLErrorUserCancelledAuthentication =     -1012,
        NSURLErrorUserAuthenticationRequired =  -1013,
        NSURLErrorZeroByteResource =        -1014,
        NSURLErrorCannotDecodeRawData =             -1015,
        NSURLErrorCannotDecodeContentData =         -1016,
        NSURLErrorCannotParseResponse =             -1017,
        NSURLErrorAppTransportSecurityRequiresSecureConnection NS_ENUM_AVAILABLE(10_11, 9_0) = -1022,
        NSURLErrorFileDoesNotExist =        -1100,
        NSURLErrorFileIsDirectory =         -1101,
        NSURLErrorNoPermissionsToReadFile =     -1102,
        NSURLErrorDataLengthExceedsMaximum NS_ENUM_AVAILABLE(10_5, 2_0) =   -1103,
    
        // SSL errors
        NSURLErrorSecureConnectionFailed =      -1200,
        NSURLErrorServerCertificateHasBadDate =     -1201,
        NSURLErrorServerCertificateUntrusted =  -1202,
        NSURLErrorServerCertificateHasUnknownRoot = -1203,
        NSURLErrorServerCertificateNotYetValid =    -1204,
        NSURLErrorClientCertificateRejected =   -1205,
        NSURLErrorClientCertificateRequired =   -1206,
        NSURLErrorCannotLoadFromNetwork =       -2000,
    
        // Download and file I/O errors
        NSURLErrorCannotCreateFile =        -3000,
        NSURLErrorCannotOpenFile =          -3001,
        NSURLErrorCannotCloseFile =         -3002,
        NSURLErrorCannotWriteToFile =       -3003,
        NSURLErrorCannotRemoveFile =        -3004,
        NSURLErrorCannotMoveFile =          -3005,
        NSURLErrorDownloadDecodingFailedMidStream = -3006,
        NSURLErrorDownloadDecodingFailedToComplete =-3007,
    
        NSURLErrorInternationalRoamingOff NS_ENUM_AVAILABLE(10_7, 3_0) =         -1018,
        NSURLErrorCallIsActive NS_ENUM_AVAILABLE(10_7, 3_0) =                    -1019,
        NSURLErrorDataNotAllowed NS_ENUM_AVAILABLE(10_7, 3_0) =                  -1020,
        NSURLErrorRequestBodyStreamExhausted NS_ENUM_AVAILABLE(10_7, 3_0) =      -1021,
    
        NSURLErrorBackgroundSessionRequiresSharedContainer NS_ENUM_AVAILABLE(10_10, 8_0) = -995,
        NSURLErrorBackgroundSessionInUseByAnotherProcess NS_ENUM_AVAILABLE(10_10, 8_0) = -996,
        NSURLErrorBackgroundSessionWasDisconnected NS_ENUM_AVAILABLE(10_10, 8_0)= -997,
    };
    

    【讨论】:

    • 嗨@MichK 请告诉我ERROR CODE = 500 的错误是什么?
    • @iPhoneDeveloper NSURLErrorBadServerResponse
    • @iPhoneDeveloper HTTP 状态码 500 ist 内部服务器错误
    【解决方案3】:

    在 SWIFT 3 中。 以下是 Swift 3 枚举中的 NSURLErrorDomain 错误代码描述: (从上面的答案复制并转换了我能做的)。

    enum NSURLError: Int {
        case unknown = -1
        case cancelled = -999
        case badURL = -1000
        case timedOut = -1001
        case unsupportedURL = -1002
        case cannotFindHost = -1003
        case cannotConnectToHost = -1004
        case connectionLost = -1005
        case lookupFailed = -1006
        case HTTPTooManyRedirects = -1007
        case resourceUnavailable = -1008
        case notConnectedToInternet = -1009
        case redirectToNonExistentLocation = -1010
        case badServerResponse = -1011
        case userCancelledAuthentication = -1012
        case userAuthenticationRequired = -1013
        case zeroByteResource = -1014
        case cannotDecodeRawData = -1015
        case cannotDecodeContentData = -1016
        case cannotParseResponse = -1017
        //case NSURLErrorAppTransportSecurityRequiresSecureConnection NS_ENUM_AVAILABLE(10_11, 9_0) = -1022
        case fileDoesNotExist = -1100
        case fileIsDirectory = -1101
        case noPermissionsToReadFile = -1102
        //case NSURLErrorDataLengthExceedsMaximum NS_ENUM_AVAILABLE(10_5, 2_0) =   -1103
    
        // SSL errors
        case secureConnectionFailed = -1200
        case serverCertificateHasBadDate = -1201
        case serverCertificateUntrusted = -1202
        case serverCertificateHasUnknownRoot = -1203
        case serverCertificateNotYetValid = -1204
        case clientCertificateRejected = -1205
        case clientCertificateRequired = -1206
        case cannotLoadFromNetwork = -2000
    
        // Download and file I/O errors
        case cannotCreateFile = -3000
        case cannotOpenFile = -3001
        case cannotCloseFile = -3002
        case cannotWriteToFile = -3003
        case cannotRemoveFile = -3004
        case cannotMoveFile = -3005
        case downloadDecodingFailedMidStream = -3006
        case downloadDecodingFailedToComplete = -3007
    
        /*
         case NSURLErrorInternationalRoamingOff NS_ENUM_AVAILABLE(10_7, 3_0) =         -1018
         case NSURLErrorCallIsActive NS_ENUM_AVAILABLE(10_7, 3_0) =                    -1019
         case NSURLErrorDataNotAllowed NS_ENUM_AVAILABLE(10_7, 3_0) =                  -1020
         case NSURLErrorRequestBodyStreamExhausted NS_ENUM_AVAILABLE(10_7, 3_0) =      -1021
    
         case NSURLErrorBackgroundSessionRequiresSharedContainer NS_ENUM_AVAILABLE(10_10, 8_0) = -995
         case NSURLErrorBackgroundSessionInUseByAnotherProcess NS_ENUM_AVAILABLE(10_10, 8_0) = -996
         case NSURLErrorBackgroundSessionWasDisconnected NS_ENUM_AVAILABLE(10_10, 8_0)= -997
         */
    }
    

    直接链接到 Swift github 存储库中的URLError.Code,其中包含正在使用的错误代码的最新列表 (github link)。

    【讨论】:

      【解决方案4】:

      我在使用 Parse 时收到错误 Domain=NSURLErrorDomain Code=-1011,并提供了错误的 clientKey。我一改正它,它就开始工作了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-11
        • 1970-01-01
        • 2023-03-03
        • 2017-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多