gpt4 book ai didi

ios - RESTKit 2.0 : AFHTTPClient with text/html

转载 作者:行者123 更新时间:2023-11-29 03:05:42 25 4
gpt4 key购买 nike

我正在使用 RESTKit v0.20.3。因为我不期待 responseObject,所以我决定使用 AFHTTPClient 进行 POST。我有以下代码:

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFJSONParameterEncoding;
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];

[httpClient postPath:@"/update" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"AFJSONRequestOperation Alt response MIMEType %@",[responseObject MIMEType]);
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"***ERROR*****: %@", [error localizedDescription]);
}];

这是我的日志

2014-04-01 16:43:01.125 App[13181:60b] E restkit.network:RKObjectRequestOperation.m:209 POST 'http://api.domain.com' (200 OK) [0.1158 s]: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html" UserInfo=0xccab6a0 {NSLocalizedRecoverySuggestion=<!DOCTYPE html><html><head><title></title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>Not Found</h1><h2>404</h2><pre>Error: Not Found
at Object.handle (/var/app/current/app.js:175:15)
at next (/var/app/current/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at pass (/var/app/current/node_modules/express/lib/router/index.js:110:24)
at Router._dispatch (/var/app/current/node_modules/express/lib/router/index.js:173:5)
at Object.router (/var/app/current/node_modules/express/lib/router/index.js:33:10)
at next (/var/app/current/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at SessionStrategy.module.exports.strategy.pass (/var/app/current/node_modules/passport/lib/middleware/authenticate.js:314:9)
at SessionStrategy.authenticate (/var/app/current/node_modules/passport/lib/strategies/session.js:61:12)
at pass (/var/app/current/node_modules/passport/lib/authenticator.js:333:31)
at deserialized (/var/app/current/node_modules/passport/lib/authenticator.js:345:7)</pre></body></html>, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xda43280> { URL: http://api.domain.com/update }, NSErrorFailingURLKey=http://api.domain.com/update, NSLocalizedDescription=Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xdd50720> { URL: http://api.domain.com/update } { status code: 200, headers {
"Content-Length" = 1083;
"Content-Type" = "text/html; charset=utf-8";
Date = "Tue, 01 Apr 2014 23:43:12 GMT";
"Proxy-Connection" = "Keep-alive";
Server = "nginx/1.4.3";
"X-Powered-By" = Express;
} }}
2014-04-01 16:43:01.126 App[13181:60b] ***ERROR*****: Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html

我得到的错误是在接收 text/html 时,但是我如何告诉 AFHTTPClient 期待 text/html

我尝试添加:

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

返回:

2014-04-01 16:48:13.110 App[13289:60b] ***ERROR*****: The operation couldn’t be completed. (Cocoa error 3840.)

如果我使用 AFHTTPRequestOperation,我该如何向它传递参数?我正在使用 RESTKit,所以我不能使用 AFNetworking 2.0。代码示例将不胜感激!

最佳答案

如果您检查 HTML 的内容,它实际上是这样的:

<h1>Not Found</h1><h2>404</h2>

所以,问题不是你请求的页面不存在,而是返回的内容类型不对。

验证您正在使用的 URL 和路径。

关于ios - RESTKit 2.0 : AFHTTPClient with text/html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22799102/

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