Call php interfaces for ios

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.