对AFNetworking的卷曲请求

时间:2014-04-08 12:34:09

标签: ios curl afnetworking

我对AFNetworking有疑问。

我有一个运行的curl请求:

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X GET -d ' {"email":"f.m.coulon@gmail.com","token":"zyWvAKwNeJ8MFGJ3DNJD"}' http://ks3290066.kimsufi.com:8888/api/activities

但是当我在我的应用程序中使用AFnetworking时,我的状态代码为303 ...

NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

NSMutableData *postBody = [NSMutableData data];
NSLog(@"%@", [NSString stringWithFormat:@" {\"email\":\"%@\",\"token\":\"%@\"}", [prefs stringForKey:@"EMAIL"], [prefs stringForKey:@"TOKEN"]]);

[postBody appendData:[[NSString stringWithFormat:@" {\"email\":\"%@\",\"token\":\"%@\"}", [prefs stringForKey:@"EMAIL"], [prefs stringForKey:@"TOKEN"]] dataUsingEncoding:NSUTF8StringEncoding]];

//post
[request setHTTPBody:postBody];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"operation hasAcceptableStatusCode: %ld", (long)[operation.response statusCode]);
    NSLog(@"response string: %@ ", operation.responseString);


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"error: %@", error);

}];

[operation start];

我不知道为什么我的请求没有运行......

有人可以帮助我吗?

0 个答案:

没有答案