您的位置:首页 > 产品设计 > UI/UE

NSURLRequest POST方式请求

2015-10-20 15:10 260 查看
NSURLRequest POST方式请求

 

1

NSString *urlString = [NSString stringWithFormat:@"http://jssb.zust.edu.cn/androidLogin.action"]; 

         NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 

         [request setURL:[NSURL URLWithString:urlString]]; 

       [request setHTTPMethod:@"POST"]; 

2头 

         NSString *contentType = [NSString stringWithFormat:@"text/xml"]; 

         [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 

3、数据内容体的设定 

NSMutableData *postBody = [NSMutableData data]; 

[postBody appendData:[[NSString stringWithFormat:@"id=%@&password=%@&role=%@",@"admin02",@"admin02",@"dean"] dataUsingEncoding:NSUTF8StringEncoding]]; 

[request setHTTPBody:postBody]; 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: