I'm new to c++, I'm learning with the book "C++ Primer"(I am at page 710) but I'm trying to learn too how to use streams from cpprestsdk.
How can I use Concurrency::streams::async_istream and
Concurrency::streams::async_ostream to take a string from the console and output that stream to console?
I have googled a lot without luck. no one use cpprestsdk today for http request and Json?
The only web who gives Info is CppRestSdk Documentation and there isn't any example about anything, and [http://msdn.microsoft.com] who gives just 3 poor examples of streams, Json and http_requests.
If I'm very lost, please help me to improve my way to learn http_requests and Json in c++ giving me advices.
Thank you!
Related
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.
What to learn to be able to send files online using c++ on windows ?
i know c++, and i got a program that does some benchmark and saves into a text file, i want that text file to be sent to me after the benchmarking is done, so what should i search for ? tried searching found something called sockets and something about server and clients in linux, kinda dunno what to search for.
this isn't a homework, just want to do it for fun xD, and would help me in future if i want someone who knows nothing about whats happening to test something for me (the file would have all i need and it will be sent to me).
I think you better off just emailing the file after a benchmark is done, and doing it using some bash or Python scripting rather than C++ or any other low level language. Here is an example of sending email using Python. Another option would be to upload to the FTP or use rsync to transfer file over SSH. And in any case, do not write your own client-server application for this.
If you still want to use C++, here is an example of sending email using POCO.
you will find some official documentation on Win32 sockets here:
http://msdn.microsoft.com/en-us/library/ms738545%28v=vs.85%29.aspx
This tutorial seems pretty good and simple:
http://johnnie.jerrata.com/winsocktutorial/
Have a nice day!
I was told I have to use winsock, but I dont know where to start. For example, I am trying to access, lets say http://www.newegg.com/, I am trying to get the text title of just the three front page products. Any help is greatly appreciated. :D
I'd also recommend libcurl for this sort of thing.
You can use the cURL command line tool to generate sample code as well, which is helpful for experimentation.
W3.org themselves provide sample C / C++ librarys for Http requests.
Find them here
Specifically, look for HTTPReq.c
Use boost library and poco. They both provide solutions for network programming. Boost also provide spirit library which you can use for parsing data from websites. Poco libraru also provides NetSSL, crypto solutions.
P.S. boost::spirit is not a library for parsing data from websites, it provides solution for parsing strings ...
you need to open a socket.
then you need to do an http get
somewhat like :-
http://www.esqsoft.com/examples/troubleshooting-http-using-telnet.htm
You could use the QNetworkAccessmanager class from Qt framework.
I'm assuming you need to use c++ for a reason, such as integration with existing software, otherwise, as per some of the other suggestions, choosing a language with a more convenient framework (eg: scripting language) would be better suited for the task.
If you would like to avoid getting your hands dirty with WINSOCK, or have the need to run on a platform other than windows, you could look at the using the boost asio library.
The following page contains links to simple sync and async http clients:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/examples.html
You can find documentation on the library itself at:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio.html
Use c++ if you must, but it might be a lot less painful to use python.
Look at the Python httplib module for how to set the host you want to pull from etc. Python's available for free for most platforms and is enough like C++ that you can probably learn python a heck of a lot faster than you can learn to write a program controlled browser in c++. Well, maybe that's not true for everyone on this site, but I'll bet it's true for "most" of us. I used to get stock quotes updated in near real time from CNN Money years ago and IIRC it was around 100 lines of python code.
Hotei
I was thinking recently about what projects I could start that would be of use to me and this came up. I post on various forums a daily updated journal entry that is the same for each forum. I also keep a log of the journal entries as individual docx files on my hard drive. I figured it would be great if I could create a program that would be given an input docx file and then post its contents as a new reply to all the daily journal threads on the forums that I have.
I am well versed in c++ for college like programming (algorithms, programming competitions, science based assignments and such), but not at all experienced with practical applications. My first question to get me started with this new idea of mine is if there are any libraries for c++ that allow for an interaction to a dynamic webpage like I described.
Thanks Much,
Michael
That problem can be approached as simply as using cURL (or a similar library) to GET pages and POST form data, or it could be as complicated as writing a Firefox XPCOM extension.
Any interaction with web page (posting a reply or tweeting or searching) is typically either POST or GET http request. As meantioned by greyfade - to construct such requests - you whouls use cURL or smth like asio from Boost library.
I'm building an application which I'd like to have it connect to a website and parse some data off it. I'm wondering if anyone could provide me some raw example code.
I don't necessarily need help parsing, I'm just wondering in C++ how would I go about downloading the data from the page into my app so that I can start parsing the data I need out of it?
Check out libCurl.
Check out boost.asio [examples].