1

How to pass form data from HTML(.html) to Web service(c#) and then registers this in a database, it's possible?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <meta charset="utf-8" />
</head>
<body>
    <form id="form1" method="post" action="#">
    <div>
        <div>
            <input id="Text1" type="text" name="username"/>
        </div>
        <div>
            <input id="Text2" type="text" name="password" />
        </div>
        <div>
            <input id="Button1" type="button" name="enviar" value="Enviar" />
        </div>
    </div>
    </form>
</body>
</html>
  • db contains a table with two fields username and password.
  • preferably json.
  • use restful.

1 Answer 1

1

Replace <form id="form1" method="post" action="#">

To <form id="form1" method="post" action="/REST_URL/OF_YOUR_CHOICE">

It will be application/x-www-form-urlencoded not json
But you don't need json here.

In your web service (assuming you are using asp.net) you need

EDIT

If you have not already done You may need to put this in web.config

<system.web>
  <webServices>
    <protocols>
      <add name="HttpPost"/>
    </protocols>
  </webServices>
</system.web>
Sign up to request clarification or add additional context in comments.

3 Comments

yes i use asp.net and my url ws is example "localhost:5406/WebService1.asmx", then in action would. action="localhost:5406/WebService1.asmx".
Yup. And you don't need the host part if you are running in the same host. ps. this doesn't looks restful to me. :-)
you should include the method you are calling as well. For example, http://localhost:5406/webservice1.asmx/CaseSensitiveMethodName

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.