当我从viewDidLoad
调用getProfile方法时- (void)viewDidLoad {
[super viewDidLoad];
[self getProfile];
}
成功
-(void)getProfile
{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSString *tempurl= [NSString stringWithFormat:@"%@11155/person/@self",baseUrlSecure];
tempurl = [tempurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:tempurl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request addValue:gWCToken forHTTPHeaderField:@"WCToken"];
[request addValue:gWCTrustedToken forHTTPHeaderField:@"WCTrustedToken"];
[request setHTTPMethod:@"GET"];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error)
{
NSLog(@"Error: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
[Alert showAlertWithTitle:@"M2All" andWithMessage:error.localizedDescription onView:self andErrorCode:[NSString stringWithFormat:@"%ld",error.code]];
});
}
else
{
NSDictionary *dictResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSArray *arrError = [dictResult objectForKey:@"errors"];
if(arrError.count >0)
{
dispatch_async(dispatch_get_main_queue(), ^{
[Alert showAlertWithTitle:@"M2All" andWithMessage:[[arrError objectAtIndex:0] objectForKey:@"errorMessage"] onView:self andErrorCode:[[arrError objectAtIndex:0] objectForKey:@"errorCode"]];
});
return;
}
}
}];
[postDataTask resume];
}
但是从webViewDidFinishLoad调用同样的错误
我不知道是什么问题
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[self getProfile];
}
答案 0 :(得分:0)
清除浏览器Cookie并重试。我遇到了类似的问题。我清除了浏览器缓存,它对我来说很好用