我已經使用Frisby框架編寫API測試用例。當我把網址和憑證到郵遞員或DHC,響應來了正常,但在弗里斯比測試用例我收到錯誤: -我收到錯誤「預計400到200」
的代碼如下: -
var frisby = require('frisby');
frisby.create('User Authentication')
//send the params to below url
.post("url",
{ username: "username",
password: "password"
},
{ json: true,
headers: {Accept:'application/json',
'Accept-Encoding':'Encoding:gzip, deflate',
'Accept-Language':'en-US,en;q=0.8',
Connection:'keep-alive',
'Content-Length':'107',
'Content-Type':'application/json',
Host:'url.com',
Origin:'http://url.com',
Referer:'http://url.com/',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
'X-Application-Key':'1234545',
'X-Requested-With':'XMLHttpRequest'
}
}
)
.expectStatus(200)
.toss();
用戶名,密碼和網址是假的。 –
任何建議請 –
HTTP 400是'不好的請求',所以請求標題可能有問題。 「接受編碼」:'編碼:gzip,deflate'看起來很奇怪;如果我是你,我會刪除第二個'Encoding:'。 –