I've recently downloaded the Poco libraries to implement a simple file upload functionality, however I'm encountering an issue where the Content-Length of the message does not get set, causing the upload to fail. Here is what I have currently:
- Code: Select all
try
{
URI uri("http://server:80/fileupload");
std::string path(uri.getPathAndQuery());
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
HTTPResponse res;
req.setHost( uri.getHost(), uri.getPort());
req.set("User-Agent", "POCO 1.3.6p2");
req.setKeepAlive(true);
HTMLForm form(Poco::Net::HTMLForm::ENCODING_MULTIPART);
FilePartSource file1("c:\\test.txt");
FilePartSource file2("c:\\test2.txt");
form.addPart("test.txt", & file1);
form.addPart("test2.txt", & file2);
form.prepareSubmit(req);
form.write(session.sendRequest(req));
session.receiveResponse(res);
std::cout << res.getStatus() << ": " << res.getReason() << std::endl;
}
catch ( Exception& ex )
{
std::cerr << ex.displayText() << std::endl;
return 1;
}
I've tried using a CountingOutputStream to determine the form size, then set the Content-Length, however this empties the FileStreams, so that the outgoing multipart message has no file content. I'm sure I'm missing something simple to determine the Form size, however I just don't see it. Any help would be greatly appreciated.
thanks,
Steve





