Mock3 moco框架的http協議post方法Mock的實現


新建一個 startupPost.json 

[
  {
    "description":"模擬一個post請求",
    "request":{
      "uri":"/postDemo",
      "method":"post"
    },
    "response":{
      "text":"這是一個post請求"
    }
  },

  {
    "description":"模擬一個帶參數的post請求",
    "request":{
      "uri":"/postwithparam",
      "method":"post",
      "forms":{
        "name":"huhanshan",
        "age":"18"
      }
    },
    "response":{
      "text":"這是一個帶參數的post請求,胡漢山帶着參數又回來了"
    }
  }
]

注意,post里面的參數和get不一樣,get是用的queries關鍵字,但是post用到的是forms關鍵字 ,他不可以在瀏覽器中看結果,因為,瀏覽器中只可以允許get請求。所以在瀏覽器訪問會出現錯誤:顯示400錯誤

如何訪問呢?需要在jmeter中看結果:

結果:

 響應數據:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM