RestKit - 无法找到 MIMEType 'text/html' 的解析器
我目前刚开始在 IOS 上使用 RestKit,并且遇到了问题。我设置了一个 JAXRS 服务调用,它从后端检索数据并以 xml 格式显示内容。因此,您将拥有一个类似于 http://www.example.com/service/clients 的网址。这将返回客户列表等。 我正在尝试使用 IOS 中的 RestKit Framework 将 xml 映射到我可以使用的对象。有谁知道一个简单的例子可以做到这一点。以下是我正在使用的大部分代码:
-(void) viewDidLoad
{
RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:@"http://www.example.com/service"];
RKObjectMapping *clientMapping = [RKObjectMapping mappingForClass:[client class]];
[clientMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[clientMapping mapKeyPath:@"firstName" toAttribute:@"firstName"];
[manager.mappingProvider setMapping:hcpMapping forKeyPath:@/clients"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/clients" delegate:self];
.....
}
对于上述内容,我收到以下错误: HTTP 状态 406 - 与接受标头不匹配 restkit.network:RKObjectLoader.m:241 无法找到 MIMEType 'text/html' 的解析器,
这似乎是从页面返回的错误,但是,我能够运行该页面,并且它返回 xml,浏览器没有任何问题。有谁知道我可能做错了什么?
I am currently new to using RestKit for IOS and had an issue. I had setup a JAXRS service call that retrieves data from the backend and displays the content in xml. So you would have a url like http://www.example.com/service/clients. This would return the list of clients etc.
I am trying to use the RestKit Framework in IOS to map the xml into an object I can use. Does anyone know of a simple example that does this. Below is the majority of the code I am using:
-(void) viewDidLoad
{
RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:@"http://www.example.com/service"];
RKObjectMapping *clientMapping = [RKObjectMapping mappingForClass:[client class]];
[clientMapping mapKeyPath:@"lastName" toAttribute:@"lastName"];
[clientMapping mapKeyPath:@"firstName" toAttribute:@"firstName"];
[manager.mappingProvider setMapping:hcpMapping forKeyPath:@/clients"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/clients" delegate:self];
.....
}
I am receiving the following error for the above:
HTTP Status 406 - No match for accept header
restkit.network:RKObjectLoader.m:241 Unable to find parser for MIMEType 'text/html'
this seems to be an error being returned from the page however, I am able to run the page and it returns xml with no problem from the browser. Does anyone know what I could have done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以解决问题。有关更多详细信息,请查看此链接。
This should do the trick. For some more details, please check this link.
尝试显式指定 XML:
Try explicitly specifying XML: