• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HTML Questions

Cogman

Lifer
So I have started a project for a C++/Apache/sqlite website that helps me keep track of some notes. It isn't going to be a big project, and I didn't want to go through the hassle of installing PHP or Perl, ect. But thats beside the point.

My question lies in the transmission of data. I would like to be able to just post all the data, but I don't know how to do that with hyperlinks (and the HTML tutorials haven't been too helpful) I could just link though the get method, but I really don't like the idea of having a huge URL string.

So is there any way to post data (send data without changing the URL) using just HTML? I want to just have to click on a link to basically navigate the database.
 
So I have somewhat accomplished what I want (functional wise) here is the generated code
<html>
<body>
<center>
<FORM action="./test.exe" method="post">
<P>
<BUTTON name="page" value="A" type="submit">A</BUTTON>
<BUTTON name="page" value="B" type="submit">B</BUTTON>
<BUTTON name="page" value="C" type="submit">C</BUTTON>
<BUTTON name="page" value="D" type="submit">D</BUTTON>
<BUTTON name="page" value="E" type="submit">E</BUTTON>
<BUTTON name="page" value="F" type="submit">F</BUTTON>

<BUTTON name="page" value="G" type="submit">G</BUTTON>
<BUTTON name="page" value="H" type="submit">H</BUTTON>
<BUTTON name="page" value="I" type="submit">I</BUTTON>
<BUTTON name="page" value="J" type="submit">J</BUTTON>
<BUTTON name="page" value="K" type="submit">K</BUTTON>
<BUTTON name="page" value="L" type="submit">L</BUTTON>
<BUTTON name="page" value="M" type="submit">M</BUTTON>
<BUTTON name="page" value="N" type="submit">N</BUTTON>
<BUTTON name="page" value="O" type="submit">O</BUTTON>

<BUTTON name="page" value="P" type="submit">P</BUTTON>
<BUTTON name="page" value="Q" type="submit">Q</BUTTON>
<BUTTON name="page" value="R" type="submit">R</BUTTON>
<BUTTON name="page" value="S" type="submit">S</BUTTON>
<BUTTON name="page" value="T" type="submit">T</BUTTON>
<BUTTON name="page" value="U" type="submit">U</BUTTON>
<BUTTON name="page" value="V" type="submit">V</BUTTON>
<BUTTON name="page" value="W" type="submit">W</BUTTON>
<BUTTON name="page" value="X" type="submit">X</BUTTON>

<BUTTON name="page" value="Y" type="submit">Y</BUTTON>
<BUTTON name="page" value="Z" type="submit">Z</BUTTON>

</P>
</FORM>
</center>
<br>
<br>
</body>
</html>

Not pretty, so if there is another way to accomplish the same functionality I would be appreciative.
 
to POST data, you typically need a form to be submitted. forms are generally submitted using submit buttons but you could also do a hyperlink. for example

<a href="foo" onclick="document.myform.submit()">A</a>
 
Typically when you want to POST data to a website/form/service you open a connection using a METHOD = POST in the headers, and then you byte encode the post data as a key=value&key2=value2 just like a GET request string would be, then you submit the data to the website/form/service via the socket established with the header request.
 
Originally posted by: Crusty
Typically when you want to POST data to a website/form/service you open a connection using a METHOD = POST in the headers, and then you byte encode the post data as a key=value&key2=value2 just like a GET request string would be, then you submit the data to the website/form/service via the socket established with the header request.

The thing is, Apache doesn't send the socket information to C++ (nor do I really want it to) so their isn't much way to control what is going on that way. With post, the data comes in the stdin. but with get it has to be processed using the getenv command.

Personally, I like dealing with stdin more then messing with the getenv stuff. But thanks for your input.
 
Apache doesn't care whether it's C++ or LISP calling it, all it knows is that someone is requesting a POST on the server. If whatever code you are using doesn't allow you to submit POST data then there's a pretty large flaw in the library.

Granted, this is C# in .NET, but you'll get the idea.

Stream ret = null;
HttpWebResponse wres = null;
byte[] data;
ASCIIEncoding encoding = new ASCIIEncoding();

data = encoding.GetBytes(postData);

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Authentication.HTTPHostName + url);

myRequest.CookieContainer = this.myCookieContainer;

myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Method = "POST";
myRequest.ContentLength = data.Length;

/* Write Data to Web Service */
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

wres = (HttpWebResponse)myRequest.GetResponse();

Now depending on the data I get back I do different things. You can do stuff like check content type to help parse the data correctly and such.

What that does is open a connection to the url presented. You have to specify your content length so the server knows how much data to expect as well as the content type so it knows HOW to decode the data. Then I just open a Stream and push my byte data down the connection. Once you've submitted all of your POST data the server will build it's response and present it to you. .NET framework takes care of all of the heavy lifting in this case, but it still shows the operations of getting data down the pipe.

By the way, what library are you using to generate the requests? You should be using libcurl 😉
 
Originally posted by: Crusty
Apache doesn't care whether it's C++ or LISP calling it, all it knows is that someone is requesting a POST on the server. If whatever code you are using doesn't allow you to submit POST data then there's a pretty large flaw in the library.

Granted, this is C# in .NET, but you'll get the idea.

Stream ret = null;
HttpWebResponse wres = null;
byte[] data;
ASCIIEncoding encoding = new ASCIIEncoding();

data = encoding.GetBytes(postData);

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Authentication.HTTPHostName + url);

myRequest.CookieContainer = this.myCookieContainer;

myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Method = "POST";
myRequest.ContentLength = data.Length;

/* Write Data to Web Service */
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

wres = (HttpWebResponse)myRequest.GetResponse();

Now depending on the data I get back I do different things. You can do stuff like check content type to help parse the data correctly and such.

What that does is open a connection to the url presented. You have to specify your content length so the server knows how much data to expect as well as the content type so it knows HOW to decode the data. Then I just open a Stream and push my byte data down the connection. Once you've submitted all of your POST data the server will build it's response and present it to you. .NET framework takes care of all of the heavy lifting in this case, but it still shows the operations of getting data down the pipe.

By the way, what library are you using to generate the requests? You should be using libcurl 😉

🙂 I think you misunderstand me. I'm not making a web server or client. I am making a program that is executed by the web server (I hesitate to say script because its compiled). My client will be firefox, so I have no control over how it handles the webpage (other then being able to control the HTML)

So yeah, im not calling apache with c++, apache is calling C++ (if that makes sense). Posting data with C++ is definitively doable (i've done it before) but that's not what my aim is. My am is to post data using my standard web browser.
 
Ah I gotcha now. I was under the impression you were calling a webform via C++. In this case, it doesn't matter what language you are writing your code in so long as it spits out HTML.

A few things to remember though is that spiders and such will willy nilly follow links on pages, so if your site has some destructive action hidden behind your link then any search engine could potentially call it. It's a general rule of web programming to put anything destructive behind a POST request using a form Submit. So just be careful with what you do.

From your code, it doesn't look like this is destructive in nature so using links and a query string via GET should be okay.

The difference between GET and POST is a lot more then just not having anything in the URL as part of the query string. For what you want, a simple <a href...> </a will do. There are right places to use GET, and this is one of them.

Think of GET like you are getting data from teh server. In order for it to give you data you need to supply it parameters via a query string. You use POST when you want to change the state of the server by posting new data to it. Two separate uses that shouldn't be mixed for various security reason.
 
Originally posted by: Crusty
Ah I gotcha now. I was under the impression you were calling a webform via C++. In this case, it doesn't matter what language you are writing your code in so long as it spits out HTML.

A few things to remember though is that spiders and such will willy nilly follow links on pages, so if your site has some destructive action hidden behind your link then any search engine could potentially call it. It's a general rule of web programming to put anything destructive behind a POST request using a form Submit. So just be careful with what you do.

From your code, it doesn't look like this is destructive in nature so using links and a query string via GET should be okay.

The difference between GET and POST is a lot more then just not having anything in the URL as part of the query string. For what you want, a simple <a href...> </a will do. There are right places to use GET, and this is one of them.

Think of GET like you are getting data from teh server. In order for it to give you data you need to supply it parameters via a query string. You use POST when you want to change the state of the server by posting new data to it. Two separate uses that shouldn't be mixed for various security reason.

Dang spiders, I didn't even think of that. (not a web developer) Thanks for the tips. I don't plan on giving it a domain, but probably am going to password protect it through an .haccess file (or is it ht? I forget).

[edit] that made little sence[/edit]
 
Back
Top