Как отправить HTML-форму из API Nodejs + Expressjs - PullRequest
0 голосов
/ 26 сентября 2019

Я использую Express для разработки API, Нужно отправить HTML-форму при вызове вызова GET API

Я добавил код ниже, он работает нормально, когда он открывается из браузера, но при вызове из Postman или Angular HTTPПОЛУЧИТЕ, что это не будет отправлять форму.

код контроллера:

  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.com&#x2f;" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail.com" /><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();
    }

Если кто-то сталкивался с тем же scenerio, пожалуйста, помогите здесь.Спасибо

Ответы [ 2 ]

1 голос
/ 26 сентября 2019

Вы можете использовать res.send("<>HTML here</>") или res.sendFile(<fileName>)

см .: https://expressjs.com/pt-br/api.html#res.send

0 голосов
/ 26 сентября 2019

пожалуйста, попробуйте этот код

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" id="WebToLeads25788000000071001" method="POST" accept-charset="UTF-8" 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.com&#x2f;" /><input type="text" name="First Name" value="MANGESH" /><input type="text" name="Last Name" value="MANGESH" /><input type="text" name="Email" value="**@gmail.com" /><input type="text" name="Mobile" value="*****" /><input type="text" name="City" value="Pune" /></form><script type="text/javascript">document.forms[\'WebToLeads25788000000071001\'].submit();</script></body></html>');
  res.end();
}

Надеюсь на его помощь

...