大佬教程收集整理的这篇文章主要介绍了node.js – POST请求正文为空或空,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
No argument passed{“Error”:{“Code”:“BadArgument”,“message”:“@R_450_10613@est body Is Null or Empty.”}}
我有一种感觉这是由Node.js异步引起的,当请求通过时我的变量仍未定义.虽然,当req.write()包含变量时怎么办呢?也许我可以插入一个延迟来确保在发送请求之前定义变量?
var https = @R_450_10613@ire('https'); var resData = ""; var options = { host: "Westus.api.cognitive.microsoft.com",port: 443,path: "/qnamaker/v2.0/kNowledgebases/<kb-key>/generateAnswer",method : 'POST',headers: { 'Content-Type': 'application/json',"Ocp-Apim-Subscription-Key":"<sub-key>",},}; bot.dialog('qnaReq',function (session,args) { //call QnA Bot and ask that bot the question var req = https.@R_450_10613@est(options,function(res) { res.on('data',function (chunk) { resData += chunk; }); res.on('error',function(E) { console.log('problem with @R_450_10613@est: ' + e.messagE); }); res.on('end',function() { if (resData.length != 75) { //75 is the length of the error I get almost every time. This line prevents the application from crashing since I am trying to access values that won't be there. var accessibleData = JSON.parse(resData); session.send(accessibleData["answers"][0]["answer"]); } else { session.send("No argument passed" + resData); } resData = ""; }); }); var postData = {question: session.message.text}; console.log(postData); //postData is defined req.write(JSON.Stringify(postData)); req.end(); }).triggerAction({ matches: 'IT Help' });
以上是大佬教程为你收集整理的node.js – POST请求正文为空或空全部内容,希望文章能够帮你解决node.js – POST请求正文为空或空所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。