gpt4 book ai didi

ios - AFNetworking - 发布请求不起作用

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

我正在使用 AFNetworking。我的大部分请求都有效,但出于某种原因,有一个请求无效。

  RRHTTPClient *client = [RRHTTPClient sharedClient];
NSLog(@"Base url: %@", client.baseURL);
// Here I get base url: http://api-ios.rabota.ru/v2/

[client postPath:responsesPath parameters:responseDic success:^(AFHTTPRequestOperation *operation, id responseObject) {

[MBProgressHUD hideHUDForView:self.view animated:YES];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@"Error: %@", [error description]);

[MBProgressHUD hideHUDForView:self.view animated:YES];

}];

我得到以下描述的错误:

Printing description of error:
Error Domain = AFNetworkingErrorDomain Code = -1011 "Expected status code in (200-299), got 500"
UserInfo = 0x15ed43e0 {
NSLocalizedRecoverySuggestion = {
"error": {
"code": 500,
"message": "Class 'ExpressResponseREST' not found"
}
}, AFNetworkingOperationFailingURLRequestErrorKey = < NSMutableURLRequest: 0x15d6c960 > {
URL: http: //api-ios.rabota.ru/express-response/ }, NSErrorFailingURLKey=http://api-ios.rabota.ru/express-response/, NSLocalizedDescription=Expected status code in (200-299), got 500, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x15ee2d50> { URL: http://api-ios.rabota.ru/express-response/ } { status code: 500, headers {
"Cache-Control" = "no-cache, must-revalidate";
Connection = "keep-alive";
"Content-Language" = ru;
"Content-Type" = "application/json; charset=utf-8";
Date = "Wed, 30 Apr 2014 11:12:22 GMT";
Expires = 0;
"Keep-Alive" = "timeout=3";
Pragma = "no-cache";
Server = "nginx/1.4.2";
"Transfer-Encoding" = Identity;
Vary = Accept;
hst = "backend-mobile";
}
}
}

API 绝对适用于相同的 JSON 和发布路径。我不明白为什么错误地得到另一个没有“v2”部分的基本 url 以及为什么我得到错误 500。

更新:

    + (RRHTTPClient *)sharedClient
{
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[RRHelper apiDomain]]];
[sharedClient setParameterEncoding:AFJSONParameterEncoding];
[sharedClient setDefaultHeader:@"Content-type" value:@"application/json"];

});

[sharedClient setDefaultHeader:@"X-Authorization" value:[[RRSession sharedSession] getSessionId]];

return sharedClient;
}

更新2:

  NSString *responsesPath   = [NSString stringWithFormat:@"/express-response/"];

NSDictionary *responseDic = @{
@"returnOfferId": returnOfferId,
@"name": name,
@"surname": surname,
@"mail": mail,
@"birthYear": @(birthYear),
@"birthDay": @(birthDay),
@"birthMonth": @(birthMonth),
@"offerExperienceYearCount": @(offerExperienceYearCount),
@"phone": phone
};

最佳答案

我认为你应该设置 contentType: "application/json"可能会有帮助,请试试这个。

关于ios - AFNetworking - 发布请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23386859/

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