使用PHP寫乙個簡易介面

2022-09-11 06:27:08 字數 3426 閱讀 8322

安裝xamppcoda,建立本地伺服器>>http://localhost/index.html

左為xampp(apache伺服器,mysql資料庫,php) 右為coda

在coda中

建立登入介面(get 和 post)和get,post接受請求介面:

>使用者名稱:<

input

type

="text"

name

="username"

>

p>

19<

br/>

20<

p align

="center"

>密 碼:<

input

type

="text"

name

="password"

>

p>

21<

br/>

22<

p align

="center"

><

input

type

="submit"

value

="登入"

/>

p>

23form

>

24body

>

25html

>

get請求 -> http://localhost/get.php?username=zhangwei&password=123456

1

<?php

2header("content-type:text/html; charset=utf-8");34

//獲取form表單值

5$username = $_get['username'];

6$password = $_get['password'];78

//判斷form表單中key

9if(isset($_get['username']) && isset($_get['password']))else

1920 }else

23//

將錯誤資訊(陣列)轉換成json型別,返回前端

24echo(json_encode($result

));25 ?>

post請求 -> http://localhost/post.php

1

<?php

2header("content-type:text/html; charset=utf-8");34

//獲取form表單值

5$username = $_post['username'];

6$password = $_post['password'];78

//判斷form表單中key

9if(isset($_post['username']) && isset($_post['password']))else

1920 }else

23//

將錯誤資訊(陣列)轉換成json型別,返回前端

24echo(json_encode($result

));25 ?>

在xcode中進行解析:

13// ios 9 解析方法

14 nsurlsession *session =[nsurlsession sharedsession];

1516 nsurlsessiondatatask *task = [session datataskwithrequest:request completionhandler:^(nsdata * _nullable data, nsurlresponse * _nullable response, nserror *_nullable error) ];

20// 啟動task

21[task resume];

2223列印結果:24

2016-04-20 21:50:40.227 get[13393:312923] ;

30success = 1;

31}

寫乙個簡易的資料爬蟲

得到所有電影的html的字串 axios在各種環境中傳送網路請求。並獲取到伺服器響應結果 const axios require axios const cheerio require cheerio async function getmoviehtml 獲取所有電影資料 async functi...

寫乙個http介面服務

主要要提供以下功能 1 可提供http介面通訊,實現服務端和客戶端的應答 2 通訊資料格式為json 3 可根據介面需求運算元據庫增刪改查 4 介面通訊過程日誌記錄 5 可與其他模組進行內部通訊 寫了以上內容後,開始考慮如何實現了。目前使用jdbctemplate實現對資料庫mysql的操作,但sp...

自己寫乙個簡易的string型別

c語言中沒有string型別,於是,在使用c語言的時候,總會用char 型別來替代string型別,但是char 和string型別還是有一定的不同的。最大的差異就是在對字串的操作上。顯然 比起char string對於字串的操作更加的簡便,比如說 1.兩個string類的變數str1和str2,我...