HttpRequest PUT content in poco library

I want to send some data from a C ++ application to the server using an HTTP PUT request. I am using the poco library for networking in my application.

I use this piece of code:

HTTPClientSession session(_uri.getHost(), _uri.getPort()); HTTPRequest req(HTTPRequest::HTTP_PUT, path, HTTPMessage::HTTP_1_1); 

Where can I set the content (file) stream when sending a request? Can someone show me an example using this library?

+7
source share
1 answer

Quote online documentation for HTTPClientSession :

sendRequest () will return an output stream that can be used to send the request body. Upon completion of sending the request body, create an HTTPResponse object and pass it to receiveResponse ().

The following snippet shows one way to use the output stream to read in a file:

 try { Poco::Net::HTTPClientSession session("www.example.com"); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_PUT, "/foo"); std::ostream& os = session.sendRequest(request); std::ifstream ifs("thefile.txt"); // missing: error handling Poco::StreamCopier::copyStream(ifs, os); // that it :-) Poco::Net::HTTPResponse response; std::istream& rs = session.receiveResponse(response); // Do something with rs... } catch (Poco::Exception& e) { std::cout << e.displayText() << std::endl; } 

Also see slides for programming a POCO network . They show, among other things, how to use the HTTPClientSession .

The POCO documentation is concise and accurate; worth reading it.

+9
source

All Articles