#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)NSDictionary *receive; //接收数据
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//--------------------------------- 创建NSURLRequest ------------------------------
NSURL *url = [NSURL URLWithString:@"http://180.76.140.22:8070/HxWebuser/register.shtml?"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:5];
//是否允许蜂窝网络下的数据请求
request.allowsCellularAccess = YES;
//请求方式
request.HTTPMethod = @"POST";
//请求内容
request.HTTPBody = [@"usrMp=15829594809&usrpwd=123456&memberTypeid=1®ip=192.168.18.165®terminal=0" dataUsingEncoding:NSUTF8StringEncoding];
//创建NSURLSession
NSURLSession *sessionA = [NSURLSession sharedSession];
//创建NSURLSessionDataTask
NSURLSessionDataTask *dataTask = [sessionA dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
id dataA = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSLog(@"dataA:%@",dataA[@"msg"]);
self.receive = dataA;
}];
//执行任务
[dataTask resume];
}
@end
post
最新推荐文章于 2024-10-26 21:39:12 发布