首先在Chapter7文件夾下再新建一個startGet.json
startget.json代碼如下,因為是get請求,所以要寫method關鍵字,有兩個,一個是有參數,一個是無參數的請求。
[{"description":"模擬一個沒有參數的get請求","request":{"uri":"/getDemo","method":"get"},"response":{"text":"這是一個沒有參數的get請求"}},{"description":"模擬一個帶參數的get請求","request":{"uri":"/getwithparam","method":"get","queries":{"name":"huhanshan","age":"18"}},"response":{"text":"這是一個帶參數的get請求,胡漢山又回來了"}} ]
啟動mock服務器;?java -jar ./moco-runner-0.12.0-standalone.jar http -p 8888 -c startupGet.json
然后在瀏覽器訪問:localhost:8888/getDemo? ? ? 這是一個不帶參數的請求
log:
然后也可以訪問:http://localhost:8888/getwithparam?name=huhanshan&age=18? ?這是一個帶參數的請求吧
log:
?