Inputting variable into website - c++

There is a giveaway happening involving codes that need to be entered, and I wanted to make a program that would generate codes that could be entered, and then put them into the online form.
1) First off, I have already created the generator using C++, and I was wondering if there was a more efficient language for generating these types of things, and algorithms in general, but this is not as important.
2) The main part that I was wondering about was if (and how) there was a way that I could take all these codes and then input them online, without doing the manual work of copy-pasting.

You can create the HTTP Request in C++ and directly send it to the server.
To do so:
Figure out what the HTML form does (there's a Firefox Plugin called "Firebug" which shows all the Requests done by a Site). If you'r lucky, the form is simple calling a PHP script via a HTTP GET or POST Request.
Build the Request in your C++ Code (have a look at this: Send Http "Post" Request To Php Code in C or C++ if you have to make a POST Request)
Send the Request
Handle the Answer
Please excuse my bad english ;)

Related

LSP server example

I have a project in which I need to write an LSP server in OCaml for a developing language.
So I did a lot of research on this but I'm having a bit of a hard time getting through it.
The Microsoft tutorial https://microsoft.github.io/language-server-protocol/specification speaks sometimes on the server side, sometimes on the client side, sometimes JSON RPC through which requests and notifications must pass between the client and the server, and all of that mixed up, plus TypeScript and not OCaml, what I want to use as a language confuses me a bit, I feel like I don't understand anything.
So I turned to code. I saw a lot of code like the one from https://github.com/facebook/flow/tree/master/src/lsp, the one from https://github.com/ocaml/ocaml-lsp but I don't understand really the code, there are a lot of files with a lot of lines, I don't know what does what.
Can you show me an example of how to initiate connection with the first initiate request, send notification in OCaml. I will use Emacs as client but I know how to do that when the server is ready. I think a little example will help me do the rest.

Using curl in C++ to get page that changes after sometime

I was trying to make a webscraper in C++ (I know I could use some other language but I'm just trying to learn). There's a webpage I'm trying to get the html code to but the page changes after a second or two with the links I want. How do I make the program wait until sometime to return the html?
Edit: I want to make a curl call once and then wait some time and then do another curl call to the same webpage after some time. (Not open the link again as it would give the same page)
You have three options:
investigate the site and figure out how the javascript code is changing the page, then replicate that in C++ (either by hard-coding a URL or parsing parts of the page),
embed a full browser engine that understands JavaScript and click the link after it changes, or
abandon C++ and use a dedicated scraping tool like CasperJS or Scrapy or wring or ...
I would inspect the page and see if you can make option 1 work, but option 3 is by far the easiest approach.

Create simple http request from chromium code

I want to collect some statistics of my chromium build and for that purpose I want to send some very simple data (for example just a string) with simple GET or POST request for example in browser startup stage in Launch browser function: link to code and in other similar places.
There is a way to write it on bare C++ with sockets and bytes but to be honest it's bad way I think.
I tried to read the documentation but without examples it's quite difficult to write code. To find example I found some usages in tests like: link to the code but still it not so easy to get really necessary part from this for very simple purpose: just to send "hello world" to the server.
Can anyone help with simple example how to use chromium api to make this simple request?
How to initialize QuickStreamRequest (or I need other Request)?
Where to get QuickStreamFactory?
Which parameters to put into Request method?
How to put request data ("hello world") into request?
Very simple example will bee cool :)

Connecting to a server in c++ and collecting information

So I am using QTCreator (5.0/5.1) and I am trying to access a website in a way that allows me to access information.
I have built a gui (as this is faily easy) but I want to know how to go about connecting to a network in c++ for my first time.
so for example:
https://btc-e.com/api/2/btc_usd/ticker
I want to get all the information present to me there and store it, the parse it, I just don't know how to connect, to the site.
someone mentioned using the #include but I'm not sure how exactly to use it as well.
If you could provide an example that would be great!
Thanks!
For this kind of task you probably want to use the more high level Qt classes to retreive the page and parse the data. Qt provides classes for both HTTP retrieval and parsing JSON data.
Network Programming with Qt
JSON Support in Qt
Read over those documents, have an attempt at writing some code, then ask specific questions, giving the example code you've tried using and what results you're getting.

How to get form data from HTML page using c++

How do I get form data from HTML page using c++, as far as the basics of post and get?
EDIT: CGI is using apache 2 on windows, I got c++ configured and tested with with apache already.
The easiest way to access form data from an HTTP request is via CGI. This involves reading environment variables which is done using the getenv function.
First of all take a look at webtoolkit.
You might want to use that to make your life easier.
Second you can read about network protocols.
Third take a look at your webserver docs, they might provide such interface to create a deamon that will allow you to read the HTTP socket and the data that is sent over it.
On another note next time you write a question try to elaborate as much as possible.
Explain the use case and provide a test case.
You may use CgiCC library that gives you want you are looking for. You may also try some C++ web framework like CppCMS.