gpt4 book ai didi

ios - AFNetworkingErrorDomainCode 1011

转载 作者:行者123 更新时间:2023-11-28 21:21:26 29 4
gpt4 key购买 nike

每当我访问我的 API 来获取一些数据时,它总是给我这个错误。

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500)"

UserInfo={AFNetworkingOperationFailingURLResponseErrorKey= { URL: http://www.mydealdoc.com/api/v8/fencerecorddata } { status code: 500, headers { "Cache-Control" = "no-cache"; Connection = close; "Content-Type" = "text/html"; Date = "Sat, 24 Sep 2016 13:10:07 GMT"; Server = "Apache/2.4.7 (Ubuntu)"; "Set-Cookie" = "laravel_session=eyJpdiI6IjQ3SEtFTEt3TmN0dUFqMzZlMFB6OGZVNjdNS240NjdBVU9lSDhcLzNzeUVnPSIsInZhbHVlIjoicXlzbURmMEd5K0hlVEgwUTU0QmhjbFN0QlpNMFdXT0VGWmZrQm1jUXFDNlhVV05EK1wvTnpNUnA2WHBualpWUjRWZVkrSGRxSlBRaHpIS05MQit6SFdnPT0iLCJtYWMiOiIwYTlmYzUwNjBmNzgwYWE3MDg5MTMyMTlhN2MwYzQ5YTU3ZDAxMmQ4YThhMjU4MDFiNjAwYjYxYTQwMzdlMWQ3In0%3D; expires=Sat, 24-Sep-2016 15:10:07 GMT; Max-Age=7200; path=/; httponly"; "X-Frame-Options" = SAMEORIGIN; "X-Powered-By" = "PHP/5.5.9-1ubuntu4.9"; } }, NSLocalizedDescription=Request failed: internal server error (500), NSErrorFailingURLKey=http://www.mydealdoc.com/api/v8/fencerecorddata}

我用谷歌搜索这个问题,他们都用这个解决方案回复我应该将响应序列化程序设置为 JSON。但是我已经设置好了。

这是我的代码。

-(void)userHasCheckThisStoreDealsWithStoreName:(NSArray *)data {
NSString *storeName = [data objectAtIndex:0];
NSString *branchName = [data objectAtIndex:1];
NSString *userID = [data objectAtIndex:2];
NSString *check = [data objectAtIndex:3];
NSLog(@"Store Name: %@",storeName);

NSDictionary *param = @{@"user_id":userID ,@"s_name":storeName , @"branch_name":branchName, @"enter_flag":check};


[BabyNetworkManager postWithUrlString:@"http://www.mydealdoc.com/api/v8/fencerecorddata" parameters:param success:^(id data){

NSError *error;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];;
NSLog(@"Dictionary = %@",responseDictionary);
if ([[responseDictionary objectForKey:@"status"] isEqualToString:@"success"]) {

}
else{
NSArray *arrayOfParamObjects = [NSArray arrayWithObjects: storeName,userID,branchName,check, nil];
[self performSelectorInBackground:@selector(userHasCheckThisStoreDealsWithStoreName:) withObject:arrayOfParamObjects];

}


} failure:^(NSError *error){

NSLog(@"Error %@",error);

}];

}

请务必阅读我在下面函数的第 3 行中提到的评论。

+(void)postWithUrlString:(NSString *)urlString parameters:(NSDictionary *)parameters success:(HttpSuccess)success failure:(HttpFailure)failure{


AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//
manager.requestSerializer = [AFJSONRequestSerializer serializer];// I have check this line by commenting and uncommenting in both state i get the same error
manager.responseSerializer = [AFHTTPResponseSerializer serializer];


manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html", nil];


[manager POST:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject){
success(responseObject);

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error){
failure(error);

}];

}

最佳答案

HTTP 500 是服务器错误,我猜这个错误是由于你发送给服务器的invalid post param 造成的,服务器端发生了一些异常。

因为我在 OC 中尝试过你的 API,所以我可以得到正确的 JSON 响应。示例代码如下:

ApiClient.m

#import "ApiClient.h"

@implementation ApiClient

+ (instancetype)sharedClient
{
static ApiClient *_sharedClient;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[ApiClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://www.mydealdoc.com"]];

_sharedClient.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
});

return _sharedClient;
}

@end

ViewController.m

#import "ViewController.h"
#import "ApiClient.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

NSDictionary *param = @{@"user_id":@"123" ,@"s_name":@"123" , @"branch_name":@"123", @"enter_flag":@"123"};

[[ApiClient sharedClient] POST:@"/api/v8/fencerecorddata" parameters:param constructingBodyWithBlock:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@", [responseObject description]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", [error localizedDescription]);
}];

}

@end

这是控制台日志:

2016-09-25 11:14:01.588 StackoverflowTestOC[3314:41971] { status = success; }

关于ios - AFNetworkingErrorDomainCode 1011,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39676746/

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