当我尝试在iOS 7的XCODE 5中使用postObject时收到此错误:
以下是没有指向https:// service
的网址的错误消息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);
答案 0 :(得分:0)
您应该显示其余的错误(显示的内容之前的行)。这是关于响应,而不是请求。 HTML响应通常意味着错误消息,您需要了解这是什么,以了解错误。
问题似乎是您在致电(_uuidURL)
时使用path
作为postObject
,但它是完整的网址。
path
应该与用于创建对象管理器的基本URL相关。即。
baseURL = @"www.myserver.com/"
path = @"mycontent"