错误域= NSURLErrorDomain代码= -1017“操作不能 [英] Error Domain=NSURLErrorDomain Code=-1017 "The operation couldn’t be
问题描述
我刚刚开始ios开发,我正在尝试与我的api交换数据。当我正在进行POST请求时一切正常,但当我尝试执行GET请求时,我收到以下错误:
I just started ios development and I'm trying to exchange data with my api. When I'm doing POST requests everything is going fine but when I'm trying to do a GET request I get the following error:
错误域= NSURLErrorDomain代码= -1017操作不能完成
。(NSURLErrorDomain错误-1017。)UserInfo = 0x145a2c00
{NSErrorFailingURLStringKey = http://myAPI.com/ ,
_kCFStreamErrorCodeKey = -1,NSErrorFailingURLKey = http://myAPI.com ,
_kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x145b21d0操作无法完成。(kCFErrorDomainCFNetwork错误
-1017。)}
Error Domain=NSURLErrorDomain Code=-1017 "The operation couldn’t be completed. (NSURLErrorDomain error -1017.)" UserInfo=0x145a2c00 {NSErrorFailingURLStringKey=http://myAPI.com/, _kCFStreamErrorCodeKey=-1, NSErrorFailingURLKey=http://myAPI.com, _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x145b21d0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1017.)"}
有人可以解释出现了什么问题以及如何解决这个问题吗?
Could someone explain what's going wrong and how I can fix it?
我的要求:
-(void)hitApiWithURL:(NSString*)url HTTPMethod:(NSString*)HTTPMethod params:(NSDictionary*)params successBlock:(successTypeBlock)success failureBlock:(errorTypeBlock)failure{
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
[sessionConfig setHTTPAdditionalHeaders:@{@"Content-type": @"application/json"}];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:HTTPMethod];
// The body
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
[request setHTTPBody:jsonData];
NSURLSessionDataTask *dataTaks = [session dataTaskWithRequest:request];
[dataTaks resume];
NSLog(@"dataTask started");
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error {
if (error) {
//Gives my error
}
else {
// do something:
}
}
推荐答案
您的JSON参数有问题:
You have something wrong with your JSON parameters:
kCFURLErrorCannotParseResponse = -1017
这篇关于错误域= NSURLErrorDomain代码= -1017“操作不能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!