Archived Forum Post

Index of archived forum posts

Question:

Duplicating a Post form with more arguments

Aug 18 '14 at 10:16

Hi there,

I need to duplicate a form like this one:

<form action="http://sumdomain.domain.ro/directory" method="post">
<input type="hidden" name="link-back" value="http://sumdomain.domain.ro/directory" readonly="readonly" />
<input type="button" value="No" onclick="document.location='http://sumdomain.domain.ro/';" />
<input type="submit" value="Yes" name="submit-disclaimer" style="margin:0 0 0 20px;" />
</form>

I thank you very much in advance!


Answer

The simplest way to duplicate the HTTP POST is via the PostUrlEncoded method, which takes two arguments: a URL and an HttpRequest object. The URL is the form's action. In this case the form action is "http://sumdomain.domain.ro/directory", which is already a full URL. If the form action is only a relative path, then you must use add the domain to make it a full URL. For example, if the form action is "/directory", and the HTML containing the form is located on "somedomain.domain.ro", then the full url would be "http://somedomain.domain.ro/directory". If you need SSL/TLS, then simply use "https://" in the URL.

Each of the "input" fields corresponds to a parameter in the HttpRequest object. Prior to calling PostUrlEncoded, construct your HttpRequest object:

Chilkat.HttpRequest req = new Chilkat.HttRequest();
req.AddParam("link-back","http://sumdomain.domain.ro/directory");
req.AddParam("submit-disclaimer","Yes");
...

If an HTML input field uses Javascript to dynamically set the name/value, then you'll need to pre-determine a correct value because there is no Javascript involved (nor is there a full HTML document involved) with the HTTP request constructed and sent via the Chilkat HTTP and HttpRequest objects.