Windows C++ Should I use WinHttp library or XmlHttp from MSXML? - c++

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.

Related

Google API Client Library for C++ vs libcurl for sending HTTP request?

After installing google-api-client library for C++ on a Fedora 20 machine, I find out that it has external dependencies on libcurl (for example, setting up http proxy). I was planning to use google-api-client for sending HTTP request, mainly, HTTP multipart POST request. However, libcurl does provide support for multipart HTTP POST request also.
Could someone let me know the advantages of using Google API Client library for C++ over libcurl in order to send HTTP request?
Any suggestions/recommendations would be highly appreciated.
Thanks
The Google API Client Library is just a C++ wrapper around libcurl which is pure C library. I would use Casablanca REST SDK which is written in modern C++11, has no external dependencies and is cross platform.

Implementing a Client using Mongoose with C++

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/

Which WinAPI library is best for uploading a file to a server

I have a WinAPI C++ application & I need to upload a file to my server. I want to use native WinAPI libraries/header files to upload the file so that my application will work on windows platforms 2000 & up & because I want to learn how to do it in win32 which I think will be fun. This means that I dont want to use a 3rd party library but learn how to do it the native WinAPI way.
Which of the following "Libraries"/Methods would be best for my needs?
- WinHTTP
- WinSock
- WinINet
Maybe there are better WinAPI libraries that I haven't mentioned aswell?
The method of uploading I would use is either TCP, HTTP or UDP but I am not sure which transfer protocol would be best for what I am doing? Which would you suggest?
Depending on the protocol, either WinHTTP or WinInet. Sockets are too low-level.
If the server supports only FTP, then WinInet. If it's HTTP upload (via POST or PUT), then WinHTTP. The thing with HTTP uploads is that there's no single, universally accepted way to do that, and server admins are often reluctant to allow for two-way HTTP file transfer. FTP, on the other hand, is a tried and true workhorse.
Obviously WinInet or WinHTTP. And using HTTP would be best.

HTTP connection through DMZ / proxy 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.

Secure data transfer over http with custom server

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.