나는 ... 나는 이상한 문제를하고있어 한이 IOS HTTP/JSON 올리기 레일 서버와 예상 출력에 대해 AFNetworking를 사용하여 뭔가 같은 : 때때로AFNetworking JSON Post에서 내가 뭘 잘못하고 있니?
{"success":true,"auth_token":"4D8CyUsyGZdqo6X1TCeq"}
그것은 종종에 예상하지만로 작동 레일 측에서는 요청이 "JSON"요청으로 감지되지 않으므로 HTML을 제공합니다. 누구나 이것에 대한 생각을 가지고 있습니까? JSON 요청을 설정하는 것과 관련하여 내가 잘못하고있는 것이 있습니까? 내 서비스를 알고
NSDictionary *parameter = @{@"email":@"[email protected]", @"password":@"mypassword"};
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://localhost:3000"]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient postPath:@"api/v1/sessions" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *jsonString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Here is what we got %@", jsonString);
NSDictionary *loginResult = [jsonString objectFromJSONString];
NSNumber* success = [loginResult objectForKey:@"success"];
NSLog(@"success = %@", success);
NSLog(@"yay");
// sample output:
// {"success":true,"auth_token":"4D8CyUsyGZdqo6X1TCeq"}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self handleConnectionError:error];
}];