【发布时间】:2014-04-11 14:11:02
【问题描述】:
当我尝试在 XCODE 5 for iOS 7 中使用 postObject 时收到此错误:
这是没有指向 https:// 服务的 URL 的错误消息
E restkit.network:RKObjectRequestOperation.m:542 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html" UserInfo=0xb9a44f0 {NSLocalizedRecoverySuggestion={"status": "ok"}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0x8dd14c0> { URL: http:
NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xb998d30>
{ status code: 200, headers {
Connection = close;
"Content-Length" = 16;
"Content-Type" = "text/html; charset=utf-8";
我在 postObject 方法中放入的任何对象都只返回 text/html 而不是 JSON。我似乎没有使用我定义的 requestDescriptor 或 requestMapping。它只是将对象发布为 text/html。
还有其他使用 RestKit 发布的方法吗?
是否有针对此问题的修复或解决方法?
这是我的代码示例:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping]; // objectClass == NSMutableDictionary
[requestMapping addAttributeMappingsFromArray:@[@"email", @"nickname"]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[RegisterDeviceInfo class] rootKeyPath:nil method:RKRequestMethodAny];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:_uuidURL]];
[RKObjectManager setSharedManager:objectManager];
[objectManager addRequestDescriptor:requestDescriptor];
RegisterDeviceInfo *deviceInfo = [RegisterDeviceInfo new];
deviceInfo.email = email;
deviceInfo.nickname = nickname;
// This is not accepted by the postObject and mapped to JSON object using above mappings and requestDescriptor
NSLog(@"deviceInfo is: %@", deviceInfo);
[[RKObjectManager sharedManager] postObject:deviceInfo path:(_uuidURL) parameters:nil success: nil failure: nil];
NSLog(@"deviceInfo is: %@", deviceInfo);
【问题讨论】:
-
Wain- 我已添加完整的错误消息。感谢您的帮助。
-
Wain: ps- 我有 Restkit 0.22.0 我会在这篇文章中更改版本