我在CCAvenue的控制器中使用以下代码,但是我收到错误
TypeError:request.on不是函数
以下是请求的代码
request.on('data', function (data) {
console.log("data is ----------------> " + data);
body += data;
encRequest = ccav.encrypt(body, workingKey);
console.log("Enc request " + encRequest);
formbody = '<form id="nonseamless" method="post" name="redirect" action="https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction"/> <input type="hidden" id="encRequest" name="encRequest" value="' + encRequest + '"><input type="hidden" name="access_code" id="access_code" value="' + accessCode + '"><script language="javascript">document.redirect.submit();</script></form>';
});
request.on('end', function () {
response.writeHeader(200, {
"Content-Type": "text/html"
});
response.write(formbody);
response.end();
});
我使用var request = require('request')
编辑:
request.post("https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction", {
form: {
encRequest: encRequest,
access_code: accessCode
}
},
function (error, response, body) {
console.log(body);
});
我的身体得到了回复,这是一个HTML页面。如何将它发送回sail.js框架中的浏览器?
编辑2: 我也尝试过使用sails.request方法,但没有回复。
var payReq = {
url: "https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction",
method: "POST",
headers: {
"Content-Type": "text/html"
// "Content-Type": 'application/json'
},
// data : {
// encRequest: encRequest,
// access_code: accessCode
// }
data : `encRequest=${encRequest}&access_code=${accessCode}`
}
sails.request(payReq);
答案 0 :(得分:2)
我认为您以不正确的方式使用请求。您正在使用的此模式适用于HTTP / HTTPS库。这是一个请求示例。
select id, first_name, last_name, city
from :customer
where id = :id
request.on(&#39;数据&#39; ..模式由Native HTTP和HTTPs库使用。示例将在此处:
https://www.twilio.com/blog/2017/08/http-requests-in-node-js.html
此页面包含使用Request,HTTP,Axios的示例。