iOS http访问post 、get
来源:互联网 发布:淘宝超市加盟 编辑:程序博客网 时间:2024/06/06 04:01
@synthesize nameFiled;//手机号@synthesize passFiled;//密码//登录时的按钮事件- (IBAction) login{//post数据的手机号及密码NSString *post = [NSString stringWithFormat:@"mobile=%@&password=%@",nameFiled.text,passFiled.text];//将post数据转换为 NSASCIIStringEncoding 编码格式 NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; //要post的联通网址 [request setURL:[NSURL URLWithString:@"http://client.10010.com/client/login.do"]];//post类型 [request setHTTPMethod:@"POST"]; //[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];//设置post数据 [request setHTTPBody:postData]; //创建链接NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];if (conn) { if (receivedData != nil) {[receivedData release];}//创建数据接收域 receivedData = [[NSMutableData alloc] initWithData:nil]; } [conn release];}#pragma mark -#pragma mark Http post 数据// 每收到一次数据, 会调用一次- (void)connection:(NSURLConnection *)aConn didReceiveData:(NSData *)data{//将接收的数据进行添加[receivedData appendData:data];}// 网络错误时触发- (void)connection:(NSURLConnection *)aConn didFailWithError:(NSError *)error{//错误的提示UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:[NSMutableString stringWithFormat:@"%@",error] delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];[alert show];[alert release];}// 全部数据接收完毕时触发- (void)connectionDidFinishLoading:(NSURLConnection *)aConn{//将data 转换成为字符串NSString *results = [[NSString alloc] initWithBytes:[receivedData bytes] length:[receivedData length] encoding:NSUTF8StringEncoding];//接收的数据UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:results delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil];[alert show];[alert release];[results release];}
0 0
- iOS http访问post 、get
- iOS-Http : GET : POST
- iOS http get和post
- iOS http get和post
- JAVA通过HTTP访问:Post+Get方式
- Http访问网络之GET和POST
- JAVA通过HTTP访问:Post+Get方式
- java通过HTTP访问:POST+GET
- HTTP(GET和POST访问URL) -- wininet
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- iOS http get和post(2)
- iOS http get和post(3)
- IOS开发 HTTP相关GET/POST请求
- ios发送http GET和POST请求
- iOS HTTP协议的get,post方法
- iOS http get和post(2)
- iOS http get和post(3)
- .tar.gz和.tar.bz2解压命令
- Oracle VM VirtualBox 打开复制虚机报错
- 关于Intent传递对象以及序列化技巧
- pulltoRefresh的开源框架使用
- MySQL中的binlog相关命令和恢复技巧
- iOS http访问post 、get
- Scroll滑动效果
- Hibernate框架学习(搭建)
- lua table 计算长度
- [android]_[绘图]
- POJ 1151(线段树+扫描线)
- [hdu2665 Kth number]区间第k大数
- 稀疏问题的学习2
- 精彩美文