标签:
NSString *account = @"UserName";
NSString * pswd = @"Pwd";
NSString * mobile = @"12345678901";
// 发送请求
NSString *urlstr = [NSString stringWithFormat:@"http://222.73.117.158:80/msg/HttpBatchSendSM?account=%@&pswd=%@&mobile=%@&msg=您好,您的验证码是123456",account,pswd,mobile];
urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlstr];
// 创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.timeoutInterval = 5.0;
request.HTTPMethod = @"POST";
// 同步请求
// NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// NSString *str1 = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
//
// NSLog(@"%@",str1);
//异步请求
__block NSString *str2 = [[NSString alloc] init];
NSOperationQueue *queue=[NSOperationQueue mainQueue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
str2 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str2);
}];
标签:
原文地址:http://www.cnblogs.com/Pegboggs/p/5000979.html