英文:
Postman send request entirely constructed in pre-requisite script
问题
我有以下一段代码,在“Pre-request Script”部分生成多个订单。
我不需要在“Body”部分放任何内容。但是只在请求体中发送 [{}] 会导致400错误。
var guid = (function() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return function() {
return 'HolCal' + s4() + '-' + s4() + '-' + s4() + '-' +
s4();
};
})();
var requestKeyNum = 2;
var orders = [];
for (var i = 0; i < requestKeyNum; i++) {
var key = guid();
orders.push({
"key": key,
"tradeDate": "2019-07-03",
"settleDate": "2019-07-04",
"transactionCode": "B",
"fundingCurrencySecurity": {
"secId": 1894823,
"secType1": "CASH",
"secType2": "NA",
"secType3": "NA",
"secType4": "NA",
"assetClass": "C",
"exchangeCode": "",
"tradeCurrencyCode": "USD",
"maturityDate": null,
"mortgageClass": null,
"investIdType": "D",
"investId": "9999USD",
"clearingHouseCode": null,
"settlementLocation": "PHY",
"expirationDate": null,
"issueCountry": ""
}
})
}
postman.setEnvironmentVariable("orders", JSON.stringify(orders));
英文:
I have this below piece of code that generates me multiple orders in Pre-request Script section.
I dont need to have anything in "Body" section. But sending just [{}] in the body gives me 400 error.
var guid = (function() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return function() {
return 'HolCal' + s4() + '-' + s4() + '-' + s4() + '-' +
s4();
};
})();
var requestKeyNum = 2;
var orders = [];
for (var i = 0; i < requestKeyNum; i++) {
var key = guid();
orders.push({
"key": key,
"tradeDate": "2019-07-03",
"settleDate": "2019-07-04",
"transactionCode": "B",
"fundingCurrencySecurity" :{
"secId":1894823,
"secType1": "CASH",
"secType2":"NA",
"secType3":"NA",
"secType4":"NA",
"assetClass":"C",
"exchangeCode":"",
"tradeCurrencyCode":"USD",
"maturityDate":null,
"mortgageClass":null,
"investIdType":"D",
"investId":"9999USD",
"clearingHouseCode":null,
"settlementLocation":"PHY",
"expirationDate":null,
"issueCountry":""
}
})
}
postman.setEnvironmentVariable("orders", JSON.stringify(orders));
答案1
得分: 1
你生成的请求体应该是什么样的?
我假设你想在请求体中发送生成的订单。
如果这是真的,你必须在请求体中引用订单变量。在请求体面板中使用{{orders}}来实现这一点。
英文:
How must your generated body look like?
I assume, that you want so send you generated orders in your body.
If its true, you must reference to the orders variable in your body. Use {{orders}} in your body panel to do this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论