Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Mac
- 줄바꿈 문자
- plugin
- Source
- context
- Windows
- GIT
- maVen
- IntelliJ
- Windows 10
- grep
- profile
- bash
- VirtualBox
- lsof
- 네트워크
- find
- ssh
- xargs
- netsh
- resource
- 단축키
- JavaScript
- vscode
- Eclipse
- port
- import
- Quartz
- tomcat
- web.xml
Archives
- Today
- Total
develog
[postman] pre-request 에서 base64 로 인코딩 후 요청하기 본문
Request > Script > Pre-request 에 함수를 등록하고 사용하기
const btoa = require('btoa');
// query string
function query_string_base64 (paramName) {
let oldValue = pm.request.url.query.get(paramName);
let newValue = btoa(oldValue);
pm.request.url.query.remove(paramName);
pm.request.url.query.add({key: paramName, value: newValue});
};
// path variable
function path_variable_base64 (...paramNames) {
paramNames.each(paramName => {
let oldValue = pm.request.url.variables.get(paramName);
let newValue = btoa(oldValue);
pm.request.url.variables.each((field) => {
if (field.key === paramName) {
field.value = newValue;
}
});
});
};
// formdata
function formdata_base64 (paramName) {
let formdata = pm.request.body.formdata;
let oldValue = formdata.get(paramName);
let newValue = btoa(oldValue);
formdata.remove(paramName);
formdata.add({key: paramName, value: newValue});
}
// body json
function bodyJson_base64 (paramName) {
let jsonBody = JSON.parse(pm.request.body.raw);
let oldValue = jsonBody[paramName];
let newValue = btoa(oldValue);
jsonBody[paramName] = newValue;
pm.request.body.raw = JSON.stringify(jsonBody);
}
// eval(`${pm.globals.get('my_utils')}`);
console.log('pm.request.url', pm.request.url.toString());
query_string_base64('email');
path_variable_base64('email', 'authCode');
// formdata_base64('formdata1');
bodyJson_base64('json_data1');
console.log('pm.request.url', pm.request.url.toString());
Globals 변수에 함수를 등록하고 사용하기
Globals 변수에 함수를 등록한다
Pre-request 에서 사용하기
// my_utils Globals 변수를 로드
eval(`${pm.globals.get('my_utils')}`);
// 로드된 함수 사용하기
query_string_base64('email');
path_variable_base64('mobileOrEmail', 'authCode');
// formdata_base64('formdata1');
// bodyJson_base64('json_data1');
Comments