我想通過RESTKit使用XML Web服務。RESTkit通信錯誤
我能夠連接到服務,但是我收到一個錯誤回如下:
error=Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type (null), got application/xml"
我已經嘗試設置內容類型標題如下,但仍然沒有得到任何改變:
AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
[client setDefaultHeader:@"Content-Type" value:RKMIMETypeXML];
希望有人可以提供幫助。
我已經包含的代碼我使用做出如下申請:
NSURL *baseURL = [NSURL URLWithString:@"http://someaddress/"];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
[objectManager setRequestSerializationMIMEType:RKMIMETypeXML];
[objectManager setAcceptHeaderWithMIMEType:RKMIMETypeXML];
RKObjectMapping *recipeMapping = [RKObjectMapping mappingForClass:[Recipe class]];
[recipeMapping addAttributeMappingsFromDictionary:@{
@"articleid" : @"ArticleId",
@"title" : @"Title",
@"url" : @"URL"
}];
// Register our mappings with the provider using a response descriptor
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:recipeMapping
pathPattern:nil
keyPath:@"Recipes"
statusCodes:[NSIndexSet indexSetWithIndex:200]];
[objectManager addResponseDescriptor:responseDescriptor];
[objectManager getObjectsAtPath:@"some/path/"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray *recipes = [mappingResult array];
NSLog(@"Loaded statuses: %@", recipes);
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Hit error: %@", [error localizedDescription]);
}];
的問題是,我仍然得到預期的內容類型(空),得到了應用/ XML的錯誤消息。
此外,我已經通過一個非常快速和簡單的示例ASIHTTP應用程序打電話到服務的URL,這是成功的。我必須錯過一些根本性的東西。
感謝
您正在混合RestKit和AFNetworking。 – Martin