写一个简单的后台,在接到app请求数据的时候,返回对应的内容:
index.php文件如下:
<?php $id = $_POST['id']; if($id==001){ echo json_encode(array('id'=>001,'name'=>'zhangsan')); } if($id==002){ echo json_encode(array('id'=>002,'name'=>'lisi')); } if($id==003){ echo json_encode(array('id'=>003,'name'=>'wangwu')); } //echo "<br/><input type='button' value='提交'/>"; ?>
在IOS端使用AFNetworking请求数据的方法如下:
-(void)datarequest{
NSString *string = @"http://mazhongwei.applinzi.com"; AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init]; NSMutableDictionary *dicc = [NSMutableDictionary dictionary];
[dicc setObject:@"" forKey:@"id"];
// [dicc setObject:@"002" forKey:@"id"]; [manager POST:string parameters:dicc success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",error);
}]; }
返回数据如下:
-- ::27.043 网络请求测试[:] {
id = ;
name = lisi;
}
以上。使用php开发一个后台,用来响应其他端请求是很容易的,容易到和打印到控制台一样。。。。。