Finally got the answer after trying for a bit. I was missing a form.write statement after prepareSubmit statement. My final code goes like this which sends post requests as well as file upload requests.
HTTPRequest request(HTTPRequest::HTTP_POST, "/fileupload/upload_file.php", HTTPMessage::HTTP_1_1); HTMLForm form; form.setEncoding(HTMLForm::ENCODING_MULTIPART); form.set("entry1", "value1"); form.set("entry2", "value2"); form.addPart("file", new FilePartSource("/home/abc/Pictures/sample.png")); form.prepareSubmit(request); HTTPClientSession *httpSession = new HTTPClientSession("localhost"); httpSession->setTimeout(Poco::Timespan(20, 0)); form.write(httpSession->sendRequest(request)); Poco::Net::HTTPResponse res; std::istream &is = httpSession->receiveResponse(res); Poco::StreamCopier::copyStream(is, std::cout);
The corresponding upload server is using standard PHP code for uploading HTML form files.