【问题标题】:Rest call from webViewDidFinishLoad cause error来自 webViewDidFinishLoad 的休息调用导致错误
【发布时间】:2016-03-08 06:36:38
【问题描述】:

当我从 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];

}

【问题讨论】:

  • 你得到了什么错误..
  • errors = ( { errorCode = CWXFR0220E; errorKey = "ERR_COOKIE_TO_TOKEN_UID_MISMATCH"; errorMessage = "CWXFR0220E: 发生安全错误,因为 WCToken 中的用户 ID 74007 与 WC_USER_ACTIVITY 中的用户 ID -1002 不匹配cookie."; errorParameters = "[74007, -1002]"; } ); }
  • 这不是一个常见的错误兄弟,请在后端检查一次
  • 后端人员说您的请求没有到达服务器
  • 他说谎,打印回声一次,

标签: ios uiwebview ios9


【解决方案1】:

清除浏览器 cookie 并重试。我遇到了类似的问题。我清除了浏览器缓存,它对我来说工作正常

【讨论】:

  • 不确定这是否真的回答了这个问题。怎么说他正在使用浏览器?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-06
  • 2022-01-08
相关资源
最近更新 更多