最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何从API Nodejs + Expressjs提交html表单

IT培训 admin 10浏览 0评论

如何从API Nodejs + Expressjs提交html表单

我正在使用Express进行API开发,需要在调用GET API调用时提交HTML表单

我添加了以下代码,从浏览器中打开它可以正常工作,但是从Postman或Angular HTTP GET调用时,它不会提交表单。

控制器代码:

  zohoFormSubmit: async (req, res, next) => {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.write('<html><body><meta http-equiv="content-type" content="text/html;charset=UTF-8"><form name="WebToLeads25788000000071001" method="POST" accept-charset="UTF-8" id="zohoForm" action="https://**.zoho.in/crm/**"><input type="text" name="****" value="**" /><input type="hidden" name="zc_gad" id="zc_gad" value="" /><input type="text" name="xmIwtLD" value="**" /><input type="text" name="actionType" value="TGVhZHM=" /><input type="text" name="returnURL" value="https&#x3a;&#x2f;&#x2f;login.sthalmatrimony&#x2f;" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail" /><input type="text" name="Mobile" value="*****" /><input type="text" name="City" value="Pune" /></form><script type="text/javascript">document.WebToLeads25788000000071001.submit();</script></body></html>');
        res.end();
    }

[如果有人遇到同一场景,请在这里帮助。谢谢

回答如下:您可以使用res.send("<>HTML here</>")res.sendFile(<fileName>)

请参阅:https://expressjs/pt-br/api.html#res.send

如何从API Nodejs + Expressjs提交html表单

我正在使用Express进行API开发,需要在调用GET API调用时提交HTML表单

我添加了以下代码,从浏览器中打开它可以正常工作,但是从Postman或Angular HTTP GET调用时,它不会提交表单。

控制器代码:

  zohoFormSubmit: async (req, res, next) => {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.write('<html><body><meta http-equiv="content-type" content="text/html;charset=UTF-8"><form name="WebToLeads25788000000071001" method="POST" accept-charset="UTF-8" id="zohoForm" action="https://**.zoho.in/crm/**"><input type="text" name="****" value="**" /><input type="hidden" name="zc_gad" id="zc_gad" value="" /><input type="text" name="xmIwtLD" value="**" /><input type="text" name="actionType" value="TGVhZHM=" /><input type="text" name="returnURL" value="https&#x3a;&#x2f;&#x2f;login.sthalmatrimony&#x2f;" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail" /><input type="text" name="Mobile" value="*****" /><input type="text" name="City" value="Pune" /></form><script type="text/javascript">document.WebToLeads25788000000071001.submit();</script></body></html>');
        res.end();
    }

[如果有人遇到同一场景,请在这里帮助。谢谢

回答如下:您可以使用res.send("<>HTML here</>")res.sendFile(<fileName>)

请参阅:https://expressjs/pt-br/api.html#res.send

发布评论

评论列表 (0)

  1. 暂无评论