ios异步登录,登录的是php写服务器,同理可以实现文件图片下载
来源:互联网 发布:快彩网彩票php源码 编辑:程序博客网 时间:2024/05/29 09:29
在使用的viewController的.h文件里实现以下协议
<NSURLConnectionDataDelegate,NSURLConnectionDelegate>
<?php
$username = $_GET["us"];
$password = $_GET["ps"];
if($username =="he"&& $password =="he")
{
echo "login ok!!!";
}
else
{
echo "oh no ! you must try again!";
}
?>
//异步登录
- (IBAction)btnAsyLogin:(id)sender {
//创建url,因为此代码是在本地测试的,所以ip为127.0.0.1,服务器为Apache
NSString * s_url = [[NSStringalloc]initWithFormat:@"http://ip/logincheck.php?us=%@&ps=%@",m_tf_userName.text,m_tf_password.text];
NSURL *url = [[NSURLalloc]initWithString:s_url];
//创建请求对象
m_data = [[NSMutableDataalloc]init];
NSURLRequest *request = [[NSURLRequestalloc]initWithURL:url];
[[NSURLConnectionalloc]initWithRequest:requestdelegate:self];
}
//接收数据,实现了NSURLConnectionDelegate协议的方法
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[m_dataappendData:data];
}
//数据接收完成,实现了NSURLConnectionDelegate协议的方法
- (void)connectionDidFinishLoading:(NSURLConnection *)connectio
{
NSString *s_result = [[NSStringalloc]initWithData:m_dataencoding:NSUTF8StringEncoding];
//处理接收到的数据
//如果包含“ok”,则登录成功,反之则失败
if ([s_result rangeOfString:@"ok"].length>0)
{
UIAlertView *alert =[[UIAlertViewalloc]initWithTitle:@"login result"message:@"login success!"delegate:selfcancelButtonTitle:@"ok"otherButtonTitles: nil];
[alertshow];
}
else
{
UIAlertView *alert =[[UIAlertViewalloc]initWithTitle:@"login result"message:@"login faile!"delegate:selfcancelButtonTitle:@"ok"otherButtonTitles: nil];
[alertshow];
NSLog(@"login faile");
}
}
- ios异步登录,登录的是php写服务器,同理可以实现文件图片下载
- iOS+PHP实现登录功能
- php 实现简单的登录
- php写一个简单的登录程序
- php写一个简易的登录表单
- 搭建 登录php服务器
- PHP 登录 FTP 服务器
- iOS json登录服务器
- Android实现服务器登录
- ajax异步登录验证实现
- 在服务器上登录注册的实现
- php 实现 简单 登录
- php实现用户登录
- php登录源码实现
- PHP实现模拟登录
- PHP实现登录验证
- PHP实现注册登录
- IOS 登录验证实现
- namespace用法
- 业余数学牛人的数学自学心得
- S3C2410 实验五—— 串口通信实验
- 日志20130701~0830
- 数据结构之线性表链式存储
- ios异步登录,登录的是php写服务器,同理可以实现文件图片下载
- 裘宗燕:C/C++ 语言中的表达式求值
- 程序员对内存的理解
- Stanford Machine Learning -- 第七讲 PCA 主成分分析
- poj 3286 How many 0's?
- linux内存管理分类
- Java Programming 2
- hadoop对于压缩文件的支持及算法优缺点
- OBJC、C函数对指针形参处理