jiwangbujiu

写一个简单的后台,在接到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:@"001" 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);
    }];
    
    
}

返回数据如下:

2016-05-22 01:47:27.043 网络请求测试[23664:1526790] {
    id = 2;
    name = lisi;
}

 

 

以上。使用php开发一个后台,用来响应其他端请求是很容易的,容易到和打印到控制台一样。。。。。

 

分类:

技术点:

相关文章:

  • 2021-07-28
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2021-10-23
  • 2022-12-23
  • 2021-09-12
猜你喜欢
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案