question

anwarjutt-5014 avatar image
1 Vote"
anwarjutt-5014 asked anwarjutt-5014 edited

Unknown error when sending post request with json body using Poco [C++]

i tried a lot to send post request with json body to firestore rest api using Poco external libraries for c++.

the get request is working probably but the post request dont give a response.

here is my function for post request:

 void Connection::post(Poco::JSON::Object::Ptr body){
     // Setup Connection
     string path{uri->getPathAndQuery()};
     if(path.empty()) path = "/";
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPMessage::HTTP_1_1);
     request.setContentType(def_request_content_type);
     request.setKeepAlive(true);
     request.setContentLength(500);
    
     // Finish Connection
     std::ostream &os = session->sendRequest(request);
     body->stringify(os);
     Poco::Net::HTTPResponse response;
     std::stringstream ss;
     std::istream& is = session->receiveResponse(response);
     Poco::StreamCopier::copyStream(is,ss);
     std::cout << ss.str(); }

and this is the function which creates json obeject:

 void Connection::send_arguments(const string message,const int index){
   Poco::JSON::Object::Ptr post_body = new Poco::JSON::Object;
   Poco::JSON::Object vars;
   Poco::JSON::Object var_types;
    
   var_types.set("stringValue", message);
   vars.set("message", var_types);
   var_types.clear();
    
   var_types.set("integerValue", index);
   vars.set("index", var_types);
   var_types.clear();  
    
   var_types.set("stringValue", def_messager);
   vars.set("messager", var_types);
   var_types.clear(); 
    
   post_body->set("fields", vars);
   post_body->stringify(std::cout);
   post(post_body);
 }

i hope someone can help me.

The error is the program stopped working and after a while i got Poco::TimeoutException exception.

my firestore api url: https://firestore.googleapis.com/v1/projects/[my project id]/databases/(default)/documents/messages?key=[my web api key];

request content type = application/json


c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Where does it stop (at sendRequest or receiveResponse)?


0 Votes 0 ·

0 Answers