나는 항상 일반 텍스트 JSON 문자열을 반환하는 기본 HTTP 서버에 연결하는 간단한 코드를 가지고 있습니다. 나는 poco :: net 라이브러리를 사용하여 gcc 4.8로 업그레이드 할 때까지 find를 사용하여 C++ 11 기능에 액세스했습니다. 여러 서버에서 시도했지만 동일한 동작이 발생하므로 클라이언트 쪽입니다.Poco HTTPClientSession.receiveResponse는 상태 200을 반환하지만 C++ 11에서는 빈 응답을 반환합니까?
응답의 상태는 200입니다. 확인을 누릅니다. 콘텐츠 길이를 확인해도 서버가 응답하는 내용과 정확히 일치하므로 응답 메시지 수신 방법이 있지만 사용 가능하지 않은 메시지입니다.
URI m_uri("http://www.bbc.co.uk");
m_uri.setPort(80);
HTTPClientSession m_session(m_uri.getHost(),m_uri.getPort());
m_session.setKeepAlive(true);
// send request
HTTPRequest req(HTTPRequest::HTTP_GET, "/news/", HTTPMessage::HTTP_1_1);
m_session.sendRequest(req);
// get response
HTTPResponse res;
istream& is = m_session.receiveResponse(res);
cout << res.getStatus() << " " << res.getReason() << " ,length = " << res.getContentLength() << " , type = " <<res.getContentType() << ", keepalive = " << res.getKeepAlive() << endl; // return 200 OK, correct content length on my real server, etc.
cout << "good " << is.good() << endl; // istream is good, but gcount is 0
// Copy response
string results;
// StreamCopier::copyToString(is, results); // Fails with c++11
is >> results;
cout << results <<endl; // blank
if (results.empty())
cout << "Error" << endl; // yep, empty.
무엇을해야할지 정말 실종됩니다. 소스에서 gcc를 사용하지 않고 최신 Poco를 컴파일하려고했습니다. 알아 내려고 노력했지만 며칠을 보냈지 만 진전이 없었습니다. MacOSX Lion에 있습니다. gcc 4.8 Poco 4.3 및 4.6이 테스트되었습니다.