常规用法如下:
const queryParams = pm.request.url.query.toObject();
不过,这种方式会把所有query的参数都获取。有时我们只需要打勾的参数,比如接口需要签名的时候,多余的参数会导致签名错误。
可以用以下方法过滤非打勾参数:
const queryParams = pm.request.url.query.toObject(true);
toObject方法签名如下:
(method) PropertyList.toObject(excludeDisabled?: boolean, caseSensitive?: boolean, multiValue?: boolean, sanitizeKeys?: boolean): any
Converts a list of Properties into an object where key is _postman_propertyIndexKey and value is determined by the valueOf function
@paramexcludeDisabled — - When set to true, disabled properties are excluded from the resultant object.
@paramcaseSensitive — - When set to true, properties are treated strictly as per their original case. The default value for this property also depends on the case insensitivity definition of the current property.
@parammultiValue — - When set to true, only the first value of a multi valued property is returned.
@paramsanitizeKeys — - When set to true, properties with falsy keys are removed.