POST获取服务器json

//

//  ViewController.m

//  store

//

//  Created by apple on 2021/11/26.

//  Copyright © 2021 apple. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

@property (retain,nonatomic) UILabel *lable;

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    _lable = [[UILabel alloc] initWithFrame:self.view.frame];

    _lable.text = @"Loading Data ....";

    _lable.font = [UIFont fontWithName:@"Arial" size:20];

    _lable.numberOfLines = 0;

    _lable.lineBreakMode = NSLineBreakByWordWrapping;

    [self.view addSubview:_lable];

    NSURL *url = [NSURL URLWithString:@"https://wl.browin.net.cn/wechat/my/json"];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];

    [request setHTTPMethod:@"POST"];

    NSURLSession *session = [NSURLSession sharedSession];

    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data,NSURLResponse *response,NSError *error)

    {

        if(error!=nil){

            NSLog(@"%@",error.description);

            

        }else{

            NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

            dispatch_async(dispatch_get_main_queue(),^{

                self->_lable.text = result;

                

            });

        }

        

    }];

    [task resume];

    

    

    

    

}



@end