2012-06-14 119 views
30

這是我第一次開發ios應用程序的經驗。我正在嘗試使用Facebook圖形API發佈一些數據。我不斷收到以下錯誤:NSURLErrorDomain錯誤代碼說明

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

我無法找到NSURLErrorDomain錯誤代碼的說明。 400錯誤代碼的含義是什麼?

回答

62

NSURLErrorDomain錯誤代碼都在這裏https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes

然而上市,只是HTTP狀態代碼(http://www.w3.org/Protocols/HTTP/HTRESP.html)返回,這意味着你已經得到的東西不對您的要求。

+3

希望我能多勞多得。 Google + Apple無法找到錯誤代碼 - 當我在每個新項目(而不是錯誤名稱)上得到蘋果公司的一個不可理解的負數時(而不是錯誤名稱),我最終會回到這個答案來查找Apple文檔頁! – Adam

+1

@Adam請確保在Google中搜索負數時將其包含在引號中。否則,短劃線被解釋爲NOT搜索運算符(即,**排除**該搜索項)。 – devios1

1

我收到錯誤域= NSURLErrorDomain代碼= -1011當使用解析,並提供錯誤的clientKey。只要我改正了這一點,它就開始工作。

8

在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, 
}; 
+0

嗨@MichK請讓我知道什麼錯誤代碼= 500? – iPhoneDeveloper

+0

錯誤代碼500意味着方法不允許。 – dark

0

採取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 
    */ 
}