1、cd /Users/sunjianfei/iOS開發/Local\ Server\ -\ Api //jar包所在文件夾 2、java -jar moco-0.11.0.jar start -p 8080 -g Configs.json
[ //驗證成功 { "request":{ "method" :"post", "uri":"/postMethod", "headers":{ "content-type":"application/json" }, "json":{ "name" :"zhangsan", "password" :"123456" } }, "response":{ "file":"response/post/postTest_response.json" } }, //驗證失敗(參數錯誤或者沒有參數) { "request":{ "method" :"post", "uri":"/postMethod" }, "response":{ "text":"default" } } ]
[ //驗證成功 { "request":{ "method" :"get", "uri":"/getTest", "queries":{ "param1":"1", "param2":"2"} }, "response":{"file":"response/get/getTest_suc_response.json"} }, //驗證失敗 { "request":{ "method" :"get", "uri":"/getTest"}, "response":{ "file":"response/get/getTest_fail_response.json"} } ]
1、headers爲application/json類型,後面是一個json "headers":{ "content-type":"application/json" }, "json":{ "name" :"zhangsan", "password" :"123456" } 2、headers爲application/x-www-form-urlencoded類型,後面是一個forms "headers":{ "content-type":"application/x-www-form-urlencoded" }, "forms":{ "name" :"zhangsan", "password" :"123456" } 3、request 請求 有14個固定的屬性: method,headers,json,factory,uri,text,cookies,xpaths, json_paths,version,file,queries,path_resource,forms。 必定要遵循這些方法。 經常使用的method(請求方式),headers(heads參數),uri(url地址),file(指定調用的請求文件),queries(請求帶參),forms(表單內容)。 4、response 響應 有12個固定屬性: status,attachment,headers,version,factory,file,text,proxy,cookies,json,latency,path_resource。 5、延遲 "response":{ "latency":{"duration": 1,"unit": "second"}, "file":"login/login_fail_response.json" }