RestKit - 无法找到 MIMEType 'text/html' 的解析器

发布于 2025-01-08 05:03:23 字数 1017 浏览 1 评论 0原文

我目前刚开始在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何处潇湘 2025-01-15 05:03:23
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
                           forMIMEType:@"text/html"];

这应该可以解决问题。有关更多详细信息,请查看链接。

[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
                           forMIMEType:@"text/html"];

This should do the trick. For some more details, please check this link.

梦里°也失望 2025-01-15 05:03:23

尝试显式指定 XML:

objectManager.serializationMIMEType = RKMIMETypeXML;

Try explicitly specifying XML:

objectManager.serializationMIMEType = RKMIMETypeXML;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文