[英]Giving error with node/fastify Unsupported Media Type: application/x-www-form-urlencoded
index.js index.js
fastify.get("/paynow", (request, reply) => {
let data = {
TXN_AMOUNT: '10', // request amount
ORDER_ID: 'ORDER_123455', // any unique order id
CUST_ID: 'CUST_1238w4' // any unique customer id
}
// create Paytm Payment
paytm.createPayment(config, data, function (err, data) {
if (err) {
// handle err
}
//store the url and checksum
let url = data.url;
let checksum = data.checksum;
// delete it from data object
delete data.url;
delete data.checksum;
/* Prepare HTML Form and Submit to Paytm */
reply.type('text/html');
reply.raw.writeHead(200, { 'Content-Type': 'text/html' });
reply.header('Content-Type', 'application/x-www-form-urlencoded');
reply.header("Access-Control-Allow-Origin", "*");
reply.header("Access-Control-Expose-Headers", "Content-Range");
reply.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
reply.raw.write('<html>');
reply.raw.write('<head>');
reply.raw.write('<title>Merchant Checkout Page</title>');
reply.raw.write('</head>');
reply.raw.write('<body>');
reply.raw.write('<center><h1>Please do not refresh this page...</h1></center>');
reply.raw.write('<form method="post" action="' + url + '" name="paytm_form">');
for (var x in data) {
reply.raw.write('<input type="hidden" name="' + x + '" value="' + data[x] + '">');
}
reply.raw.write('<input type="hidden" name="CHECKSUMHASH" value="' + checksum + '">');
reply.raw.write('</form>');
reply.raw.write('<script type="text/javascript">');
reply.raw.write('document.paytm_form.submit();');
reply.raw.write('</script>');
reply.raw.write('</body>');
reply.raw.write('</html>');
reply.raw.write('ok')
reply.raw.end();
});
});
fastify.post('/true', (request, reply) => {
console.log('*')
paytm.validate(config, request.body, function (err, data) {
console.log(data)
if (err) {
// handle err
console.log(err)
}
if (data.status == 'verified') {
// mark payment done in your db
}
});
});
Paynow API is working fine but when it redirects to /true route it giving error Paynow API 工作正常,但是当它重定向到 /true 路由时出现错误
{"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type: application/x-www-form-urlencoded"}
{"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type: application/x-www-form-urlencoded"}
I think it is related to fastify really don't know as it is my first project with fastify.我认为它与 fastify 有关真的不知道,因为这是我第一个使用 fastify 的项目。 Any help will be appricated
任何帮助将被应用
index.js index.js
fastify.get("/paynow", (request, reply) => {
let data = {
TXN_AMOUNT: '10', // request amount
ORDER_ID: 'ORDER_123455', // any unique order id
CUST_ID: 'CUST_1238w4' // any unique customer id
}
// create Paytm Payment
paytm.createPayment(config, data, function (err, data) {
if (err) {
// handle err
}
//store the url and checksum
let url = data.url;
let checksum = data.checksum;
// delete it from data object
delete data.url;
delete data.checksum;
/* Prepare HTML Form and Submit to Paytm */
reply.type('text/html');
reply.raw.writeHead(200, { 'Content-Type': 'text/html' });
reply.header('Content-Type', 'application/x-www-form-urlencoded');
reply.header("Access-Control-Allow-Origin", "*");
reply.header("Access-Control-Expose-Headers", "Content-Range");
reply.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
reply.raw.write('<html>');
reply.raw.write('<head>');
reply.raw.write('<title>Merchant Checkout Page</title>');
reply.raw.write('</head>');
reply.raw.write('<body>');
reply.raw.write('<center><h1>Please do not refresh this page...</h1></center>');
reply.raw.write('<form method="post" action="' + url + '" name="paytm_form">');
for (var x in data) {
reply.raw.write('<input type="hidden" name="' + x + '" value="' + data[x] + '">');
}
reply.raw.write('<input type="hidden" name="CHECKSUMHASH" value="' + checksum + '">');
reply.raw.write('</form>');
reply.raw.write('<script type="text/javascript">');
reply.raw.write('document.paytm_form.submit();');
reply.raw.write('</script>');
reply.raw.write('</body>');
reply.raw.write('</html>');
reply.raw.write('ok')
reply.raw.end();
});
});
fastify.post('/true', (request, reply) => {
console.log('*')
paytm.validate(config, request.body, function (err, data) {
console.log(data)
if (err) {
// handle err
console.log(err)
}
if (data.status == 'verified') {
// mark payment done in your db
}
});
});
Paynow API is working fine but when it redirects to /true route it giving error Paynow API工作正常,但是当它重定向到/ true路由时会出现错误
{"statusCode":415,"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE","error":"Unsupported Media Type","message":"Unsupported Media Type: application/x-www-form-urlencoded"}
{“状态代码”:415,“代码”:“ FST_ERR_CTP_INVALID_MEDIA_TYPE”,“错误”:“不支持的媒体类型”,“消息”:“不支持的媒体类型:application / x-www-form-urlencoded”}
I think it is related to fastify really don't know as it is my first project with fastify.我认为它与fastify有关,真的不知道,因为这是我第一个与fastify合作的项目。 Any help will be appricated
任何帮助将被申请
For completeness, I needed something other than those two (I needed multipart/related).为了完整起见,我需要这两个以外的东西(我需要多部分/相关)。 You can add your own content type parser using 'addContentTypeParser' on the Fastify instance.
你可以在 Fastify 实例上使用 'addContentTypeParser' 添加你自己的内容类型解析器。
https://www.fastify.io/docs/latest/Reference/Server/#addcontenttypeparser https://www.fastify.io/docs/latest/Reference/Server/#addcontenttypeparser
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.