***************************

#import "HMViewController.h"
#import "MBProgressHUD+MJ.h" @interface HMViewController ()
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *pwd;
- (IBAction)login;
@end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
} - (IBAction)login {
// 1.用户名
NSString *usernameText = self.username.text;
if (usernameText.length == ) {
[MBProgressHUD showError:@"请输入用户名"];
return;
} // 2.密码
NSString *pwdText = self.pwd.text;
if (pwdText.length == ) {
[MBProgressHUD showError:@"请输入密码"];
return;
} /** 接口文档:定义描述服务器端的请求接口
1> 请求路径URL:客户端应该请求哪个路径
* http://localhost:8080/MJServer/login 2> 请求参数:客户端要发给服务器的数据
* username - 用户名
* pwd - 密码 3> 请求结果:服务器会返回什么东西给客户端
*/ // 3.发送用户名和密码给服务器(走HTTP协议)
// 创建一个URL : 请求路径
NSString *urlStr = [NSString stringWithFormat:@"http://localhost:8080/MJServer/login?username=%@&pwd=%@",usernameText, pwdText];
NSURL *url = [NSURL URLWithString:urlStr]; // 创建一个请求
NSURLRequest *request = [NSURLRequest requestWithURL:url]; // 发送一个同步请求(在主线程发送请求)
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSLog(@"%@", data);
}
@end

最新文章

  1. C#中try catch中throw ex和throw方式抛出异常有何不同
  2. 彻底明白IP地址——IP地址的介绍
  3. Delphi的Win32的API调用简单介绍
  4. HDU-3549 最大流模板题
  5. Flip Game(dfs)
  6. 安装sass时,gem在国内不能安装的解决
  7. 面试题_125_to_133_Java 面试中其他各式各样的问题
  8. iOS事件机制(一)
  9. ACM hdu 1019 Least Common Multiple
  10. POJ - 3608 Bridge Across Islands【旋转卡壳】及一些有趣现象
  11. 快速下单!简化EcStore的购物结算流程
  12. shell队列实现线程并发控制(转)
  13. ORACLE中 大量数据插入表 SQL
  14. JDBC数据库连接参数备忘
  15. linux用法总结
  16. Philosopher’s Walk(递归)
  17. 【Python】CentOs7 Python3安装Openssl以及解决ssl问题
  18. CTF之MD5
  19. HDU 1994 利息计算 数学题
  20. CSU 1355 地雷清除计划

热门文章

  1. TCP拆包粘包之分隔符解码器
  2. SpringJDBC解析2-execute方法
  3. jQuery方法注意事项
  4. mongodb学习05 操作详解(3)
  5. Swift3.0语言教程使用字符串创建和初始化字符串
  6. ios 简单的倒计时验证码数秒过程实现
  7. 我的c++学习(7)引用和复制构造函数
  8. 学习angularjs时遇到 XX is not a function
  9. JS运动基础
  10. SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int