NSURLConnection Authorization Header not Working

后端 未结 4 1773
别那么骄傲
别那么骄傲 2021-02-01 06:16

I am trying to send an OAuth access token in an HTTP header via NSURLConnection but it doesn\'t seem to be sending the header because the API keeps giving me an error saying tha

4条回答
  •  无人共我
    2021-02-01 06:54

    For me it look fine. Are you sure you gave a valid token? Try catch the error like this

    if (error) {
        NSLog(@"error : %@", error.description);
    }
    

    My code work well :

    NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://....ID=%i", cellID]];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:jsonURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0];
    [request setValue:@"Basic ...." forHTTPHeaderField:@"Authorization"];
    NSURLResponse *response;
    NSError * error  = nil;
    NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    

    hope it helps

提交回复
热议问题