- Code: Select all
std::string strURI = "http://porsche.herokuapp.com/api/addphotoboothimage";
Poco::URI uri(strURI);
std::string path(uri.getPath());
Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPMessage::HTTP_1_1);
session.setKeepAlive(true);
//std::string body = "{\"uuid\":\"3e8abe18-1881-46a7-8c55-6ba1e8841937\",\"photobooth\":\"xxxx\"}";
//std::string body = "uuid=3e8abe18-1881-46a7-8c55-6ba1e8841937";
//req.setContentLength(body.length());
req.setContentType(Poco::Net::HTMLForm::ENCODING_MULTIPART);
//std::cout<<"Host: "<<uri.getHost()<<" path: "<<uri.getPath()<<"\njson = "<<body<<std::endl;
Poco::Net::HTMLForm form(Poco::Net::HTMLForm::ENCODING_MULTIPART);
//form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);d18ff4f7-4eb9-4e95-bfc5-e141ec1d9d7b
//form.add("uuid", "3e8abe18-1881-46a7-8c55-6ba1e8841937");
form.add("uuid", "d18ff4f7-4eb9-4e95-bfc5-e141ec1d9d7b");
Poco::Net::FilePartSource * png = new Poco::Net::FilePartSource("E:\\of_release_v0071_vs2010\\examples\\empty\\emptyExample\\bin\\data\\image_to_upload.jpg", "application/octet-stream");
png->headers().set("uuid", "d18ff4f7-4eb9-4e95-bfc5-e141ec1d9d7b");
form.addPart("photobooth", png);
form.prepareSubmit(req);
std::ostream & send = session.sendRequest(req);
req.write(std::cout);
form.write(send);
//send << body <<"\n";
Poco::Net::HTTPResponse response;
//response.setContentType("application/octet-stream");
//response.setTransferEncoding("charset=utf-8");
std::istream & res = session.receiveResponse(response);
std::ostringstream stream;
Poco::StreamCopier::copyStream(res, stream);
std::cout<<stream.str()<<std::endl;
Actually, It does not upload successful.Does any one can help me?





