0

I am using Express for API development, Needs to submit HTML form on calling GET API call

I have added below code, it's working fine when its opened from the browser but when calling from Postman or Angular HTTP GET it will not submit a form.

controller code :

  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();
    }

If any one came across the same scenerio please help here. Thanks

2 Answers 2

1

You can use res.send("<>HTML here</>") or res.sendFile(<fileName>)

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

Sign up to request clarification or add additional context in comments.

Comments

0

please try this code

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();
}

Hope its help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.