Upload a file using POCO-SSL Connection Unexpectedly Closed

Please post support and help requests here.
Posts: 4
Joined: 15 Jul 2014, 14:37

Upload a file using POCO-SSL Connection Unexpectedly Closed

Postby nehagupta » 15 Jul 2014, 14:54

Upload a file to a HTTPS url using POCO HTTP POST request always returns "SSL Connection Unexpectedly Closed" Exception

Below is the code i am using for Multipart upload of a file..

Code: Select all

      Poco::URI uri(uploadLink);
        const Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
        Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);

      // prepare path
        std::string path(uri.getPathAndQuery());
       if (path.empty())
            path = "/";
      std::cout<<"\nPath: "<<path;

      std::ifstream f1 (filePath,std::fstream::binary);
    std::string content((std::istreambuf_iterator<char>(f1)), std::istreambuf_iterator<char>());

    std::cout<<"\n Fle Content: "<<content;

    std::string boundary = "-------------------------87142694621188";
    std::string data1("---------------------------87142694621188\r\nContent-Disposition: form-data; name=\"data\"; filename=\"");
    std::string data2(filePath);
   std::string data3("\";\r\nContent-Type: application/octet-stream\r\n\r\n");
    std::string data4("\r\n---------------------------87142694621188--\r\n");
   std::string reqBody = data1 +data2 +data3 + content + data4;
   std::cout<<"\nReq Body: "<<reqBody.c_str();
   Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path,   Poco::Net::HTTPMessage::HTTP_1_1);
   req.setContentType("multipart/form-data; boundary=-------------------------87142694621188");
        // sends request, returns open stream
        std::ostream& myOStream = session.sendRequest(req);
        // sends the body
        myOStream << reqBody;
        Poco::Net::HTTPResponse res;
        // get the response body from server
        std::istream& inStream = session.receiveResponse(res);
        std::ostringstream outStringStream;
        outStringStream << inStream.rdbuf();
        std::cout<< outStringStream.str();

    catch (Poco::Exception& e)
       std::cout <<"Upload Exception: "<< e.displayText() << std::endl;

I also tried with Html forms:

Code: Select all

 Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, path,   Poco::Net::HTTPMessage::HTTP_1_1);
    Poco::Net::HTMLForm form;
    form.addPart("file", new Poco::Net::FilePartSource(filePath));

    session.setTimeout(Poco::Timespan(20, 0));
   session.setKeepAliveTimeout(Poco::Timespan(20, 0));

    Poco::Net::HTTPResponse res;
    std::istream &is = session.receiveResponse(res);
    Poco::StreamCopier::copyStream(is, std::cout);
      std::cerr << is.rdbuf();

But both ways returns the same error.
Upload through other platforms is working, so i can say its not the server issue, but the issue is in the above code. Please help me with the issue.
Note: Server does not support chunked transfer. And the server side error log says "Bad transfer encoding: chunked". Although i am not doing chunked transfer.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests