Home > Backend Development > PHP Tutorial > 关于ios 调用php接口

关于ios 调用php接口

WBOY
Release: 2016-06-23 13:13:11
Original
1812 people have browsed it

持续在写应用  准备对服务器数据库进行交互了

所以开始测试php服务器的接口写法 

IOS使用的是afnetworking php用的是thinkphp进行测试的

代码方面

    AFHTTPRequestOperationManager*manager =        [AFHTTPRequestOperationManagermanager];

//添加一个格式 直接发送给php text/html格式 php可以免解码json格式了

    manager.responseSerializer.acceptableContentTypes=     [manager.responseSerializer.acceptableContentTypessetByAddingObject:@"text/html"];

//注册信息 因为是测试所以就是简单的写了一下

    NSDictionary*Dic = [NSDictionarydictionaryWithObjectsAndKeys:@"xx",@"User",@"123",@"PassWord",nil];

    [managerPOST:urlparameters:Dicsuccess:^(AFHTTPRequestOperation*operation,idresponseObject) {

NSLog(@"%@",responseObject);

}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

NSLog(@"%@",error);

}];

php 服务器方面

    $api = D('api');

    $data = array(

    'User'=>$_POST['User'],

    'PassWord'=>$_POST['PassWord']

    );

    if($api->add($data)){

    $state = 1;

    }else{

    $state = 2;

    }

    $array = array(

    'state'=>$state

    );

    echo json_encode($array);

如果添加成功就返回1 如果失败就返回2

创建返回值数组 将状态赋值给它  转换成json格式 输出返回,

测试用代码写的很烂勿喷

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template