Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行前脚本,post提交的参数能去掉吗,这边在把post内容转成base64编码后,需要把原有的参数删除,试了runapi.delParam等方法,有方法能去除掉吗? #2117

Closed
davieee opened this issue Dec 18, 2023 · 3 comments

Comments

@davieee
Copy link

davieee commented Dec 18, 2023

//如果是post请求,则需转成base64
if(runapi.getMethod() == 'post'){
var all_param = runapi.getAllParam();

//处理参数
var post_data={};
for(var i = 0;  i < all_param.length; i++){
    index = all_param[i]['name']
    if(index!=''){
        if(runapi.getParam(index) == "{{USERNAME}}"){
            post_data[index] = runapi.getVar("USERNAME")
        }else{
            post_data[index] = runapi.getParam(index)
        }
       //runapi.moveParam(index) 在这里执行方法去除掉不提交
    }
}

//转成json字符串后再进行base64编码
var post_json = JSON.stringify(post_data);
var base64_data = runapi.CryptoJS.enc.Utf8.parse(post_json ).toString(runapi.CryptoJS.enc.Base64);  
runapi.setParam("base64_data",base64_data )

}

@davieee
Copy link
Author

davieee commented Dec 18, 2023

runapi.setParam("name","") // 根据name设置请求表单(放在Body里的)的一个参数
将值设置成空后,也是会有这个参数上传

@star7th
Copy link
Owner

star7th commented Dec 18, 2023

我第一次听说这种会删除掉参数的需求。个人感觉是非常少数的需求。建议服务端忽略其他多余参数即可。或者接口一开始就应该设置为 post json的方式,而非表单的方式

@davieee
Copy link
Author

davieee commented Dec 18, 2023

image
这边通过runapi测试的时候,是这样传的,转成base64编码就通过执行前脚本来处理了,不过问题不大,到时候前端不传这些参数就好

@star7th star7th closed this as completed Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants