1

I wrote a C++ program that sends an http GET request to a given host and receives the answer. My program does not support POST requests. I know that form parameters can be appended at the end of the path like so:

Normal link: http://finance.yahoo.com/q/hp
Link with form parameters: http://finance.yahoo.com/q/hp?s=SNIVX&b=1&a=00&c=1900

Receiving the answer to a request with the second link works fine so far. I tried the same on this website but it doesn't seem to accept the form parameters:

http://www.finanzen.net/historische-kurse/Linde?inTag1=1&inMonat1=1&inJahr1=2010&inTag2=30&inMonat2=1&inJahr2=2015&strBoerse=XETRA

I looked up the keys and values in the page source of that website. When I click the corresponding button on the website to submit the form it uses a POST request unlike the previous example which uses a GET request. With a normal GET request it just returns the page as if no form parameters were given.

I'm using http 1.0 and winsock for the client-server communication. My request is built like this:

sprintf(htmlRequest, "GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", file.c_str(), host.c_str());

Can I somehow submit form parameters on the second website without using a POST request? Do some websites only accept/ support form parameters from POST requests and not from GET requests?

snollygolly
  • 1,858
  • 2
  • 17
  • 31

1 Answers1

0

If your resource needs to be accessed via the POST method, you should pass your parameters in the body of the HTTP request, not the query string.

Your request should look like this:

GET /historische-kurse/Linde HTTP/1.0\r\n
Host: www.finanzen.net\r\n
Connection: close\r\n
\r\n
inTag1=1&inMonat1=1&inJahr1=2010&inTag2=30&inMonat2=1&inJahr2=2015&strBoerse=XETRA

Read more about the structure of a HTTP request.

Read more about the POST method.

P.S.: FYI, the authors of that second page are abusing the POST method. POST is supposed to be used when the request can cause a change in a resource's state, however in this situation nothing's being changed, we're just reading data. Unfortunately, this type of thing is very common among web developers, people lack a basic understanding of the HTTP protocol and use its methods incorrectly all the time.

nicebyte
  • 1,498
  • 11
  • 21
  • I tried sending the http request you posted, but it results the same response as the one without form parameters. I used GET and POST, added Content-Length and Content-Type and other fields that are used in the http request that I capture when clicking the button in firefox, but no success so far. Might there be a problem with the cookies that page is using? I am not sure how cookies work exactly, but client and server are exchanging some data about cookies. – Peter Ramsauer2 Jan 31 '15 at 20:49
  • It's possible that the server is looking at cookies before sending the response. Cookies are sent from the client using the `Cookie` HTTP header. The server sets the client's cookies with the `Set-Cookie` HTTP header. In your case it seems like the following approach might work: `GET` the page without any parameters, parse the server's response and extract the values of `Set-Cookie` header(s). Then use them to set the value of your `Cookie` header when making the `POST` request. This is a bunch of work, so using a library like libcurl might help you out a lot. – nicebyte Feb 02 '15 at 05:44
  • You can read more about how cookies work in the official RFC document (http://tools.ietf.org/html/rfc6265#section-5.2) or in the Wikipedia article (http://en.wikipedia.org/wiki/HTTP_cookie) – nicebyte Feb 02 '15 at 05:45