NSURLRequest setting the HTTP header

后端 未结 6 2054
名媛妹妹
名媛妹妹 2020-12-12 12:21

I need to set the HTTP header for a request. In the documentation for the NSURLRequest class I didn\'t find anything regarding the HTTP header. How can I set the HTTP header

6条回答
  •  天涯浪人
    2020-12-12 13:04

    Sample Code

     - (void)reqUserBalance:(NSString*)reward_scheme_id id:(NSString*)user_id success:(void (^)(id responseObject))success failure:(void (^)(id responseObject))failure{
    
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@reward/%@/user/%@/balance",URL_SERVER,reward_scheme_id,user_id]];
        NSLog(@"%@",url);
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
    
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [request setValue:@"true" forHTTPHeaderField:@"Bypass"];
    
        [NSURLConnection sendAsynchronousRequest:request
                                           queue:[NSOperationQueue mainQueue]
                               completionHandler:^(NSURLResponse *response,
                                                   NSData *data, NSError *connectionError)
         {
                             options:kNilOptions error:NULL];
    
             if (data.length > 0 && connectionError == nil)
             {
                 NSDictionary * userPoints = [NSJSONSerialization JSONObjectWithData:data
                                                                          options:0
                                                                            error:NULL];
    
                 NSString * points = [[userPoints objectForKey:@"points"] stringValue];
                 NSLog(@"%@",points);
                 [SecuritySetting sharedInstance].usearAvailablePoints = points;
    
    
             }
         }];
    
    }
    

提交回复
热议问题