gpt4 book ai didi

ios - 获取操作时的 REstkit 错误

转载 作者:行者123 更新时间:2023-11-29 13:01:54 24 4
gpt4 key购买 nike

我正在执行 Restkit GET 操作,但 Restkit 出现错误。我在 Chrome 上使用 REST 控制台尝试了相同的操作,它有效:

GET 操作的细节是:网址:https://www.ez-point.com/ezpoints操作:GET授权 header :xxxxxxxxxxxxxxxxxxxxxx

借助 Chrome REST 控制台,它可以正常工作,我得到了 JSON 格式的正确响应。

对于 Restkit,它不起作用。这些是我的 Restkit 代码:

//trying restkit
NSURL *endpoint = [NSURL URLWithString:@"https://www.ez-point.com/"];
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURL:endpoint];
[objectManager.HTTPClient setAuthorizationHeaderWithToken:@"xxxxxxxxxxxxxxxxxxx"];
[objectManager getObjectsAtPath:@"ezpoints" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"Success");
//NSLog(mappingResult);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failure");
//NSLog(operation);
//NSLog(error);
}];

我收到这个错误:

2013-10-25 11:00:11.690 EZ-POINT[1089:c07] I restkit:RKLog.m:34 RestKit logging initialized...
2013-10-25 11:00:12.820 EZ-POINT[1089:c07] I restkit.network:RKObjectRequestOperation.m:180 GET 'https://www.ez-point.com/ezpoints'
2013-10-25 11:00:14.184 EZ-POINT[1089:4507] E restkit.network:RKObjectRequestOperation.m:576 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=0x110a3560 {AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://www.ez-point.com/ezpoints>, NSErrorFailingURLKey=https://www.ez-point.com/ezpoints, NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x110b42b0>}
2013-10-25 11:00:14.185 EZ-POINT[1089:4507] E restkit.network:RKObjectRequestOperation.m:243 GET 'https://www.ez-point.com/ezpoints' (401 Unauthorized / 0 objects) [request=0.0000s mapping=0.0000s total=1.3657s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html" UserInfo=0x110a3560 {AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://www.ez-point.com/ezpoints>, NSErrorFailingURLKey=https://www.ez-point.com/ezpoints, NSLocalizedDescription=Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x110b42b0>}
2013-10-25 11:00:14.599 EZ-POINT[1089:c07] Failure

有什么建议吗?

最佳答案

错误已经给出了提示:它默认不接受“text/xml”作为内容类型。现在,它接受

  • 应用程序/x-www-form-urlencoded
  • 应用程序/json

您可以使用 RKMIMETypeSerialization 注册它,并将“text/xml”添加到接受的内容类型之一:

[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:RKMIMETypeTextXML];
[objectManager setAcceptHeaderWithMIMEType:@"text/xml"];

关于ios - 获取操作时的 REstkit 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19583395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com