Cocoa 错误 3840
Cocoa error 3840
我正在尝试使用 AFNetworking 2.0
向服务器发送 post 请求
NSDictionary * dict = @{@"credentials": @{
@"name": @"Valod",
@"password": @"test"
}
};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager POST:URL parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];`
但我收到错误
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fd6214a5d70 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fd62150ec60 "Request failed: internal server error (500)"}
我用 google 测试 api 调用 application.And 响应 json 有效 json
检查你的 requestSerializer,也许它是 AFHTTPRequestSerializer 而不是 AFJSONRequestSerializer。
尝试设置 manager.requestSerializer = [AFJSONRequestSerializer serializer];
我正在尝试使用 AFNetworking 2.0
NSDictionary * dict = @{@"credentials": @{
@"name": @"Valod",
@"password": @"test"
}
};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
[manager POST:URL parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];`
但我收到错误
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x7fd6214a5d70 {NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fd62150ec60 "Request failed: internal server error (500)"}
我用 google 测试 api 调用 application.And 响应 json 有效 json
检查你的 requestSerializer,也许它是 AFHTTPRequestSerializer 而不是 AFJSONRequestSerializer。
尝试设置 manager.requestSerializer = [AFJSONRequestSerializer serializer];