objective-c - 405 不允许的方法

标签 objective-c ios box-api

我正在尝试访问https://api.box.com/2.0/files但我收到 Expected status code in (200-299), got 405在我的回复中(来自 AFNetworking)。

在发送请求之前,我已从服务器获取了我的 auth_token。

代码

- (void)getFileListing:(NSString*)apiKey
{
    if(apiKey == nil) { apiKey = kBoxNetApiKey; }

    NSDictionary *boxAuth = [[NSUserDefaults standardUserDefaults] objectForKey:kBoxNetUserDefaultsKey];

    if([boxAuth objectForKey:@"auth_token"] != nil) {
        NSURL *url = [NSURL URLWithString:@"https://api.box.com/2.0/files"];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request setHTTPMethod:@"GET"];

        DLog(@"auth_token: %@", [boxAuth objectForKey:@"auth_token"]);
        DLog(@"apiKey: %@", apiKey);

        NSString *auth = [NSString stringWithFormat:@"BoxAuth api_key=%@&auth_token=%@", apiKey, [boxAuth objectForKey:@"auth_token"]];
        [request setValue:auth forHTTPHeaderField:@"Authorization"];

        AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

            DLog(@"JSON: %@", JSON);

        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {

            DLog(@"error: %@", error);
            DLog(@"JSON: %@", JSON);

        }];

        [operation start];
    }
}

*错误

__29-[BoxNetAuth getFileListing:]_block_invoke_081 [Line 75] error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 405" UserInfo=0xa0b8740 {NSLocalizedRecoverySuggestion={"type":"error","status":405,"code":"method_not_allowed","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Method Not Allowed","request_id":"183259878350bcd62a62f1b"}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://api.box.com/2.0/files>, NSErrorFailingURLKey=https://api.box.com/2.0/files, NSLocalizedDescription=Expected status code in (200-299), got 405, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xa6c9840>}

最佳答案

您无法对 https://api.box.com/2.0/files 执行 GET 操作因为它需要一个资源 ID,例如: 获取https://api.box.com/2.0/files/12345

您可以发帖至https://api.box.com/2.0/files/content上传新文件,或者您可以 GET https://api.box.com/2.0/folders/0获取根文件夹

关于objective-c - 405 不允许的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687840/

相关文章:

iphone - 如何从我的代码访问 iPhone 的设置?

ios - Xcode : sqlite3_step returning 101, 但不在 block 内执行代码

ios - 如何将 Swift CocoaPods 与桥接头文件集成

objective-c - NS条件死锁

objective-c - NSPredicate - 无法为谓词生成 SQL,我想知道为什么?

java - Android - Box-API 只是挂起?

box-api - Box v1 api 何时停止运行?

python - 如何在python中获取Box的授权码

ios - Objective-C:NSArray与NSMutableArray的格式

ios - 如何使用 Xcode 7 将项目添加到 subversion 并更改用户凭据