I know how to implement a server with Mongoose, in fact all information that I could find was about servers, but I need to know how do I implement a client.
Very basic, how to connect to a server is the main problem, the send functions are pretty straight forward.
Mongoose is a web server and AFAIK does not provide an API for client side http requests.
For C++ http client libraries, you might want to look at these answers:
What C++ library should I use to implement a HTTP client?
A better C++ HTTP client library
These sites also give a good overview about available C++ client libraries:
http://curl.haxx.se/libcurl/competitors.html
http://en.cppreference.com/w/cpp/links/libs
Mongoose actually does provide HTTP client functionality. See mg_connect() on http://cesanta.com/docs/API.shtml. Also, example HTTP client code is at https://github.com/cesanta/mongoose/tree/master/examples/http_client
I suggest using Fossa library (a superset of Mongoose), as it's HTTP client interface is more flexible. Example code is at https://github.com/cesanta/fossa/tree/master/examples/restful_client , documentation is at http://cesanta.com/docs/fossa/
Related
I need to implement a SIP websocket client using c++. I have npm SIP websocket server. I want to test the connection using c/c++. Is there any easy to use libraries available to implement SIP websocket client in c/c++ ?
If course there is. Have a look at WebSocket++.
As to exactly how to do it - I wouldn't know since I don't know the SIP protocol. But I'll venture a guess that you need to use binary frames in WebSocket. The server, which you say already exists, obviously has implemented it - and its documentation should contain some information on how to interface with it.
Hello I'm trying to do a POST using boost::asio but I'm unable to do so. I'm looking at this example code: http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/example/http/client/sync_client.cpp How can I make this code using POST instead of GET?
asio works on the transportation layer (e.g. tcp sockets) not on the application level. Your solution would be more maintainable if you select a wide-spread http client library instead of implementing the http protocol yourself.
curl, poco and cpp-netlib is mentioned frequently here at SO but there are tons of available clients.
Have a look at these comparisons:
http://curl.haxx.se/libcurl/competitors.html
C/C++ HTTP Client Library for Embedded Projects
http://kukuruku.co/hub/cpp/a-cheat-sheet-for-http-libraries-in-c
I want to connect from webserver via dedicated proxy to the intranet. I am not sure if it matters I want to send and receive XML. It would be great if I could use HTTP.
I know of one open port 78xx which I successfully used with a TCP socket as described in this excellent tutorial
Is it possible? Or does the answer depend on the actual proxy configuration - if it scans for the protocol, and dislikes it it's gonna be blocked!?
And what library would you recommend? I just found pion - Can i link it statically? It's almost not possible to install sth on the web server for me.
EDIT My question is probably two-fold:
First, I have to add, there is an existing communication client+server, but the server is a mixup of the concrete socket and networking implementation and the API to the database, consisting of about 10 commands I find hard to extend. So I ask for a generic lib so I can rewrite that API from scratch.
Second, I need session handling, the webapplication passes the user login data to that client and there is a session-id returned which is used for all further communication - until it expires. That was the reason I asked for HTTP, but meanwhile i realized http itself is stateless.
The answer is.... in progress.- I need to practice more with c++ tcp libs etc.
My post was unfortunately hard too understand, Had some confusion about that all.
A rather simple question. Should I use the WinHttp library to make a web service request in my C++ programs or should I use the IXmlHttpRequest interface in the msxml library to send web service requests? Obviously the WinHttp library provides a lot more fine control compared to the IXmlHttpRequest library. But the XmlHttpRequest object is a w3.org standard and in theory more portable.
It depends whether you are accessing the service on secure channel i.e. HTTPS or simple one i.e. HTTP.
As per MSDN (http://msdn.microsoft.com/en-us/library/ms891732.aspx), IXMLHttpRequest supports only HTTP.
Note IXMLHTTPRequest does not support secure website access. To access a secure website, use the WinINet API.
But WinInet API is quite old and have some multi-threading issues (I think its there on MSDN too)...
So the best bet is WinHTTP for HTTPS and HTTP, otherwise good old IXMLHttpRequest.
Note: libcurl and curlpp (c++ port of libcurl) is also there to check. There is an old post for this http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c
Simple answer to your "simple question": You should use what you feel most comfortable in and what best fits to your requirements.
You could also consider the http client in boost::asio.
I am pretty new to security aspect of application. I have a C++ window service (server) that listens to a particular port for http requests. The http requests can be made via ajax or C# client. Due to some scope change now we have to secure this communication between the clients and custom server written in C++.
Therefore i am looking for options to secure this communication. Can someone help me out with the possible approaches i can take to achieve this.
Thanks
Dpak
Given that you have an existing HTTP server (non-IIS) and you want to implement HTTPS (which is easy to screw up and hard to get right), you have a couple of options:
Rewrite your server as a COM object, and then put together an IIS webservice that calls your COM object to implement the webservice. With this done, you can then configure IIS to provide your webservice via HTTP and HTTPS.
Install a proxy server (Internet Security and Acceleration Server or Apache with mod_proxy) on the same host as your existing server and setup the proxy server to listen via HTTPS and then reverse proxy the requests to your service.
The second option requires little to no changes to your application; the first option is the better long-term architectural move.
Use HTTPS.
A good toolkit for securing your communication channel is OpenSSL.
That said, even with a toolkit, there are plenty of ways to make mistakes when implementing your security layer that can leave your data open to attack. You should consider using an existing https server and having it forward the requests to your server on the loopback channel.
It's reasonably easy to do this using either OpenSSL or Microsoft's SChannel SSPI interface.
How complex it is for you depends on how you've structured your server. If it's a traditional style BSD sockets 'select' type server then it should be fairly straight forward to take the examples from either OpenSSL or SChannel and get something working pretty quickly.
If you're using a more complex server design (async sockets, IOCP, etc) then it's a bit more work as the examples don't tend to show these things. I wrote an article for Windows Developer Magazine back in 2002 which is available here which shows how to use OpenSSL with async sockets and this code can be used to work with overlapped I/O and IOCP based servers if you need to.