I am not well versed in c++, just a disclamer.  I have muddled through
creating a small client and I want to post the binary output via
HTTP.  Here is the source I have so far:

#define CURL_STATICLIB
#include <iostream>
#include <fstream>
#include <string>
#include "mvm.pb.h"
#include "curl/curl.h"
#include "curl/types.h"
#include "curl/easy.h"

using namespace std;

int main(int argc, char* argv[]) {
        // Verify that the version of the library that we linked against is
        // compatible with the version of the headers we compiled against.
        GOOGLE_PROTOBUF_VERIFY_VERSION;

        mvm::protobuf::prov::prov prov;
        mvm::protobuf::prov_Artifact* artifact = prov.mutable_object();
        mvm::protobuf::prov_Execution* action = prov.mutable_action();
        artifact->set_uuid("foo");
        artifact->set_classification("unclassified");
        action->set_action(mvm::protobuf::prov_Action_CREATED);
        mvm::protobuf::prov_Actor* actor = action->mutable_performedby();
        mvm::protobuf::prov_Person* person = actor->mutable_person();
        person->set_uuid("person_uuid");
        mvm::protobuf::prov_TimeStamp* timestamp = action-
>mutable_performedat();
        timestamp->set_datetime(1234567890);

        fstream output("mvm.out", ios::out | ios::trunc | ios::binary);
        ostrstream os; // <- what to use here?
        if (!prov.SerializeToOstream(&output)) {
                cerr << "Failed to write mvm." << endl;
                return -1;
        }
        if (!prov.SerializeToOstream(&os)) {
                cerr << "Failed to write mvm to os." << endl;
                return -1;
        }
        CURL *curl;

        curl = curl_easy_init();
        char *url = "http://localhost:8080/Protobuf/PostServlet";;
        curl_easy_setopt(curl, CURLOPT_URL, url);
        struct curl_httppost *formpost=NULL;
        struct curl_httppost *lastptr=NULL;
        curl_formadd(&formpost, &lastptr,
                        CURLFORM_COPYNAME, "mydata",
                        CURLFORM_PTRCONTENTS, "test\0test", // <- should
point to &os
                       CURLFORM_CONTENTSLENGTH, 50, // <- need to know the
size of &os
                       CURLFORM_END);
        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

        curl_easy_perform(curl);
        curl_easy_cleanup(curl);

    // Optional:  Delete all global objects allocated by libprotobuf.
    google::protobuf::ShutdownProtobufLibrary();

    return 0;
}


I added comments where I am having trouble.  I basically just wan to
populate the body (content) of the HTTP post message with the binary
output of the SerializeToOStream call.  Any help would be greatly
appreciated!

Birch

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to