Ios calls the php interface and keeps writing applications to prepare to interact with the server database.
So I started to test the php server interface writing method.
For IOS, afnetworking php is used for thinkphp testing.
Code
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManagermanager];
// Add a format and send it directly to php text/html format. php can decode json format without any need.
Manager. responseSerializer. acceptableContentTypes = [manager. responseSerializer. acceptableContentTypessetByAddingObject: @ "text/html"];
// The registration information is a test, so it is simply written.
NSDictionary * Dic = [NSDictionarydictionaryWithObjectsAndKeys: @ "xx", @ "User", @ "123", @ "PassWord", nil];
[ManagerPOST: urlparameters: Dicsuccess: ^ (AFHTTPRequestOperation * operation, idresponseObject ){
NSLog (@ "% @", responseObject );
} Failure: ^ (AFHTTPRequestOperation * operation, NSError * error ){
NSLog (@ "% @", error );
}];
Php Server
$ 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 );
If the ADD operation is successful, 1 is returned. if the ADD operation fails, 2 is returned.
Create an array of returned values to convert the status value to json format and return the result,
Code writing for testing is terrible.