Write a simple interface using PHP

Source: Internet
Author: User

Install XAMPP and Coda, create local servers >>http://localhost/index.html

   

Left for XAMPP(Apache server, MySQL database, PHP) right for Coda

  in the Coda Create Login interface (Get and Post) and Get,post Accept request Interface:

  

1 <!--  login.php  -2 3 <HTML>4     <Head>5         <MetaCharSet= "Utf-8"/>6         <title>My Web</title>7     </Head>8     9 <!------------------------------------- -Ten  One     <Body> A         <!--POST Request - -         <formMethod= "POST"Action= "http://localhost/post.php"> -  the         <!--GET Request - - <!--<form method= "Get" action= "http://localhost/get.php" > -  - -             <PAlign= "Center">User name:<inputtype= "text"name= "username"> </P> +             <BR/> -             <PAlign= "Center">Password<inputtype= "text"name= "Password"> </P> +             <BR/> A             <PAlign= "Center"><inputtype= "Submit"value= "Login"/></P> at         </form> -     </Body> - </HTML>

  Get request- http://localhost/get.php?username=zhangwei&password=123456

1<?PHP2     Header("content-type:text/html; Charset=utf-8 ");3     4     //get Form form value5     $username=$_get[' username '];6     $password=$_get[' Password '];7     8     //determine key in form form9     if(isset($_get[' username ']) &&isset($_get[' Password '])){Ten          One         //Judging username and password A         if($username= = "Zhangwei" &&$password= = "123456"){ -              -             $result=Array("Success" = 1, "Code" = 101, "Data" =Array("username" =$username, "Password" =$password));  the          -}Else{ -             $result=Array("Success" = 0, "code" = 103, "Data" =NULL); -         } +          -}Else{ +         $result=Array("Success" = 0, "code" = +, "data" =NULL); A     } at     //Convert error message (array) to JSON type, return to front end -     Echo(Json_encode ($result)); -?>

POST request, http://localhost/post.php

1<?PHP2     Header("content-type:text/html; Charset=utf-8 ");3     4     //get Form form value5     $username=$_post[' username '];6     $password=$_post[' Password '];7     8     //determine key in form form9     if(isset($_post[' username ']) &&isset($_post[' Password '])){Ten          One         //Judging username and password A         if($username= = "Zhangwei" &&$password= = "123456"){ -              -             $result=Array("Success" = 1, "Code" = 101, "Data" =Array("username" =$username, "Password" =$password));  the          -}Else{ -             $result=Array("Success" = 0, "code" = 103, "Data" =NULL); -         } +          -}Else{ +         $result=Array("Success" = 0, "code" = +, "data" =NULL); A     } at     //Convert error message (array) to JSON type, return to front end -     Echo(Json_encode ($result)); -?>

Parsing in Xcode:

1Nsurl *url = [Nsurl urlwithstring:@"http://127.0.0.1/post.php?username=zhangwei&password=123456"];2 /*  3 Nsurl *url = [Nsurl urlwithstring:@]http://127.0.0.1/post.php"];4 */5 6Nsmutableurlrequest *request = [Nsmutableurlrequest requestwithurl:url cachepolicy: Nsurlrequestuseprotocolcachepolicy timeOutInterval:Ten];7 8Request. HttpMethod =/*@ "POST"*/ @"GET";9 Ten /* One request. Httpbody = [@ "username=zhangwei&password=123456" datausingencoding:nsutf8stringencoding]; A */ -     //IOS 9 parsing method -Nsurlsession *session =[Nsurlsession sharedsession]; the  -Nsurlsessiondatatask *task = [Session datataskwithrequest:request completionhandler:^ (NSData * _Nullable data, Nsurlresponse * _nullable response, Nserror *_nullable Error) { -Nsdictionary *dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil]; -NSLog (@"%@", dict); +     }]; -     //Start Task + [Task resume]; A  at Printing results: - 2016-04-20 21:50:40.227 get[13393:312923] { - code = 101;  - data = { - password = 123456;  - username = Zhangwei;  in     };  - success = 1;  to }                                          

Write a simple interface using PHP

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.