How to send POST request to some website using winapi? - c++

I'd like to send HTTP POST request to website and retrieve the resultant page using winapi. How can I do that?

The MSDN docs have sample code using WinHTTP:
IWinHttpRequest::Send Method
Posting Data to the Server

Also consider using something like Libwww or libcurl.

You'll need to use Winsock (basically the Windows version of Berkeley sockets), create & send the HTTP request and receive & parse the response.

Related

gsoap restful c++ client using streaming

How to write a gsoap restful C++/Solaris client, which should send a document(xsd__base64Binary) to webservice using streaming?
We tried writing a gsoap restful client without streaming and it is working fine. We generated a request xml (serialization- soap_begin_send(--), soap_serialize(--), soap_put(--),soap_end_send(--)) using gsoap and then used soap_post_connect(---), soap_send(---),soap_end_send(---) to send the request.
We used MTOM for streaming in gsoap client and working fine.
Is it possible to stream a document in gsoap restful client? Can we use MTOM in restful case?
If yes, could you please let us know, what are all the gsoap functions I should use for serialization and then to send that xml request?
And also, please share if you have any sample code.
One way is take doc as string and send that string as arguments to server.
soapcpp2 will generate code for client/server for you.
See here for more details.
I agree with this but if you have document which is huge size than you can devide it in part. Create your own header-data combination and devide document in packet and send as string.

Tool to intercept RESTful webservices

May be this has been asked before but i coud'nt find a proper tool to do this.
What is the best tool to place in the middle of a RESTful webservice and monitor it without port redirection.
Something like TCPMON which will show the full request from the client and the response from the server. For example if the response contain a JSON i should be able to view that??
Charles Proxy is great for logging the full request/response for HTTP connections.

Google channel api for c/c++ client

Is there a c/c++ client for google channel api?
Well, you could probably write your own client, since my understanding is that it's "just" HTTP and JSON.
There's an outstanding feature request that Google is resolutely ignoring to get alternative client APIs.
No. The only official client is witten in Javascript.
You can write an own client using libCURL for your HTTP requests and json-cpp to read/write JSON with C++.
See if this helps. Google has recently announced new C++ API for almost all their services:
https://google-api-client-libraries.appspot.com/resources/api-libraries/documentation/compute/v1beta15/cpp/latest/

HTTP-GET-to-HTTP-POST proxy

I'm writing a Yahoo Pipe that requires communication with a specific web service. Unfortunately, the web service only accepts POST, and the Yahoo Pipes Web Service JSON POST module issues the POST in the wrong format.
So ideally, there would be some proxy somewhere on the internet that accepts a GET, takes some parameters, and converts that to a POST, then returns the results. Any ideas if something like this exists?
Thanks.
Have you seen this code?

Are there any CURL alternatives for C++?

I hate CURL it is too bulky with too many dependencies when all I need to do is quickly open a URL. I don't even need to retrieve the contents of the web page, I just need to make the GET HTTP request to the server.
What's the most minimal way I can do this and don't say CURL !##$
There are lots of choices! Try libwww -- but be warned, most people strongly prefer libcurl. It's much easier to use.
There's a very light way and I've done this myself when implementing a high-scale back end service for a large media provider in the UK.
This method is extremely operating-system specific.
open a TCP socket to the HTTP server
send a "GET /path/to/url HTTP/1.1\r\nHost: www.host.com\r\n\r\n" (the Host header is required for HTTP/1.1 and most virtual servers, don't forget the two blank lines, and a newline requires a carriage return as well for HTTP headers)
wait for the response
close the socket
If you are going to close the socket at the end of the connection you may also want to send a Connection: close\r\n as part of your headers to inform the web server that you will terminate the connection after retrieving the web page.
You may run into trouble if you're fetching an encoded or generated web page in which case you'll have to add logic to interpret the fetched data.
On Windows (Windows XP, Windows 2000 Professional with SP3 and above) you could use WinHttpReadData API. There's also an example at the bottom of that page.
More info on Windows HTTP Services on MSDN
I have used Winsock when I need as few dependencies as possible and it has worked well. You need to write more code than using a separate library or the Microsoft WinHTTP library.
The functions you need are WSAStartup, socket, connect, send, recv, closesocket and WSACleanup.
See sample code for the send function.
system("wget -q -O file.htm http://url.com");