post异步请求

时间:2022-11-03 16:42:46

//创建url

NSURL *url = [[NSURL alloc] initWithString:@"http://api.hudong.com/iphonexml.do"];

//创建可变的url请求
    NSMutableURLRequest *mRequest = [[NSMutableURLRequest alloc] initWithURL:url];

//设置请求方式为POST
    mRequest.HTTPMethod = @"POST";

//设置请求参数
    NSString *sendString = @"type=focus-c";
    mRequest.HTTPBody = [sendString dataUsingEncoding:NSUTF8StringEncoding];

//发送异步请求
   [NSURLConnection sendAsynchronousRequest:mRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
       NSLog(@"%@", data);
   }];