I have some simple code that is supposed to connect to a basic http server which responds with a JSON string. This worked find with earlier versions of gcc but I had to change to use c++11 for the project. Everything in the tens of thousands of liens of code work as before except the receiveResponse does not return an input stream with data.
The status is 200 OK but the Istrream is just blank. This seems to cause the StreamCopier::copyToString to fail with with malloc/pointer errors ( see bottom of post).
The code is very standard, here it is cleaned up and the URL changed to bbc.co.uk
Code: Select all
// send request
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
// get response
istream &is = m_session.receiveResponse(res);
// here is normally some error checking but for this post I just cout the status and get 200 OK
cout << res.getStatus() << " " << res.getReason() << endl;
// Copy response
// StreamCopier::copyToString(is, results); // Fails with c++11 (malloc/pointer error)
is >> results; // Works for results string is empty.
cout << results <<endl; // blank
Stream Copier Error:
Code: Select all
atlasTest(31646) malloc: *** error for object 0x1006c2840: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal SIGABRT, Aborted.
0x00007fff8855982a in __kill ()
#0 0x00007fff8855982a in __kill ()
#1 0x00007fff8798ba9c in abort ()
#2 0x00007fff879ea84c in free ()
#3 0x00007fff8ef71702 in std::string::_Rep::_M_dispose ()
#4 0x00007fff8ef72424 in std::string::reserve ()
#5 0x00007fff8ef7262b in std::string::append ()
#6 0x000000010081f17f in Poco::StreamCopier::copyToString ()
..... // function that does the http request as above
tested a few different URI and the same issue, I get a status 200 OK but no actual response. Everything was fine pre c++11 installation but I cannot go back to that now.
I downloaded the latest Poco Source from here and compiled/installed but that made no difference.
I spent a couple of hours searching google and trying a few things but to no avail so now I am lost. If I can't get this working we will have to drop Poco and look elsewhere, which is a shame because I really liked the clean API and simplicity!
Any idea what is going on? Any help much appreciated!