我在请求中指定了API方法,例如GET。我可能想根据我的Postman预请求脚本中的某些逻辑将其值更改为其他值(即PUT)。有没有一种方法可以在调用API调用(URL)之前以编程方式更改Method,而不必事先将Method设置为变量名?
我看到我可以通过使用邮递员对象“ request.method”获得Method的当前值。我希望将其保留为默认值(即GET),因此对所有人可见。唯一的例外是,有时我需要覆盖它并将其设置为其他内容(即PUT,OPTIONS)。我只是没有看到一种设置它的方法,除非它的值以变量(即TEMPMETHOD)开头。从用户的角度来看,尽管方法/ URI使得它很难看清其初衷,因为它改为显示了变量名。
// Get the current request method (i.e. may return GET, POST, ...)
console.log("Current request.method [" + request.method + "];");
// Want some command to overwrite the current request method regardless of its current value but I know of none UNLESS the current request method is a variable and I'd like to avoid that.
// INSERT SOLUTION HERE PLEASE :-)
// BUT I know of no solution to overwrite unless the Method starts off defined as a variable (i.e. {{TEMPMETHOD}}). I then control its value within the pre-request script.
pm.environment.set("TEMPMETHOD","OPTIONS");