-1

I have a server application using Poco C++ library to handle HTTP requests. I cannot really find much documentation or examples on how to return a CSV file from the HTTP server. Has anyone done this?

In essence this is what I have so far, but I do not understand how to return the text as a CSV file.

/// Return a CSV document.
class GetCSVFileHandler: public HTTPRequestHandler
{
public:
    GetCSVFileHandler()
    {          
    }

    void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
    {        
        std::string result = "1,2,3\n a,b,c\n";

        // ??????????????????????????????????????????????????
        // how to return a CSV file here?
        // ??????????????????????????????????????????????????
        std::ostream& ostr = response.send();
        ostr << result;
    }   
};
1
  • Can you give some details: what is exactly the problem?
    – Patricklaf
    Apr 16, 2018 at 9:56

1 Answer 1

1

Try this:

// Return a CSV document.
class GetCSVFileHandler: public HTTPRequestHandler
{
public:

    void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
    {

        response.setChunkedTransferEncoding(true);
        response.setContentType("text/csv");

        std::string result = "1,2,3\n a,b,c\n";
        std::ostream& ostr = response.send();
        ostr << result;
    }   
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.