AFNetworking 2和Parse:错误404

时间:2014-04-29 17:30:43

标签: ios parse-platform afnetworking-2

我一直在尝试使用他们的REST API和AFNetworking与Parse.com沟通。 (我没有使用他们的iOS SDK因为我想使用Core Data而且似乎不允许这样的事情)
无论如何,我几天前开始学习AFNetworking并遇到了一个问题 - 我总是得到404错误。

这是AFHTTPSessionManager的简单子类:

#import "ParseHTTPClient.h"

static NSString * const ParseAppID = @"---";
static NSString * const ParseRESTAPI = @"---";
static NSString * const ParseURLString = @"https://api.parse.com/v1/";

@implementation ParseHTTPClient

+ (ParseHTTPClient *)sharedClient
{
    static ParseHTTPClient *_sharedParseHTTPClient = nil;

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedParseHTTPClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:ParseURLString]];
    });

    return _sharedParseHTTPClient;
}

- (instancetype)initWithBaseURL:(NSURL *)url
{
    self = [super initWithBaseURL:url];

    if (self) {
        self.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

        self.requestSerializer = [AFJSONRequestSerializer serializer];
        [self.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [self.requestSerializer setValue:ParseAppID forHTTPHeaderField:@"X-Parse-Application-Id"];
        [self.requestSerializer setValue:ParseRESTAPI forHTTPHeaderField:@"X-Parse-REST-API-Key"];
    }

    return self;
}

- (void) addTodo
{
    NSDictionary *parameters = @{@"description":@"Hello World!"};
    self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", nil];
    [self POST:@"classes/Todo" parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"Yay! %@",responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"Error! %@",error);
    }];
}

@end

不幸的是,当我调用addTodo时,我将其注销:

  

错误!错误域= NSCocoaErrorDomain代码= 3840"操作   无法完成。 (可可误差3840。)" (周围的值无效   字符0.)UserInfo = 0x8f6db80 {NSDebugDescription =无效值   在字符0周围,NSUnderlyingError = 0x8f6c600"请求失败:不是   发现(404)"}

我一直在寻找解决方案几天,并作为最后的手段来到这里..请帮助(:
谢谢!

0 个答案:

没有答案