gpt4 book ai didi

ios - AFHTTPSessionManager 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:26 29 4
gpt4 key购买 nike

我正在使用 Afnetworking Framework,但每次我点击网络服务时,响应总是如下所示-

Error Domain=com.alamofire.error.serialization.response Code=-1011 “请求失败:未授权 (401)” UserInfo={com.alamofire.serialization.response.error.response

我已经使用了下面的代码谁能帮帮我-

 NSString * finalUlr =  [kMainUrl stringByAppendingString:url];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[manager.requestSerializer setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];
[manager POST:finalUlr parameters:Patameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: Success");
completionBlock(YES,responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
completionBlock(NO,nil);
}];

最佳答案

试试这个

NSString * finalUlr =  [kMainUrl stringByAppendingString:url];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:finalUlr] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];

[request setHTTPMethod:GET_METHOD]; // or POST_METHOD
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"1f76f057-1809-0bfd-5b53-f2f6c2d3ab81" forHTTPHeaderField:@"postman-token"];
[request setValue:@"qW9Bf_-RxXFz8mtxDqUYYzBN2V9N6he_tOTbSgJskVA" forHTTPHeaderField:@"x-csrf-token"];

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
if (responseObject)
{

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

[op start];

希望对你有帮助

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

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