本文整理汇总了C++中HTTPResponse::getReason方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPResponse::getReason方法的具体用法?C++ HTTPResponse::getReason怎么用?C++ HTTPResponse::getReason使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse::getReason方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
ofHttpResponse ofURLFileLoader::handleRequest(ofHttpRequest request) {
try {
URI uri(request.url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
HTTPResponse res;
ofPtr<HTTPSession> session;
istream * rs;
if(uri.getScheme()=="https"){
//const Poco::Net::Context::Ptr context( new Poco::Net::Context( Poco::Net::Context::CLIENT_USE, "", "", "rootcert.pem" ) );
HTTPSClientSession * httpsSession = new HTTPSClientSession(uri.getHost(), uri.getPort());//,context);
httpsSession->setTimeout(Poco::Timespan(20,0));
httpsSession->sendRequest(req);
rs = &httpsSession->receiveResponse(res);
session = ofPtr<HTTPSession>(httpsSession);
}else{
HTTPClientSession * httpSession = new HTTPClientSession(uri.getHost(), uri.getPort());
httpSession->setTimeout(Poco::Timespan(20,0));
httpSession->sendRequest(req);
rs = &httpSession->receiveResponse(res);
session = ofPtr<HTTPSession>(httpSession);
}
if(!request.saveTo){
return ofHttpResponse(request,*rs,res.getStatus(),res.getReason());
}else{
ofFile saveTo(request.name,ofFile::WriteOnly,true);
char aux_buffer[1024];
rs->read(aux_buffer, 1024);
std::streamsize n = rs->gcount();
while (n > 0){
// we resize to size+1 initialized to 0 to have a 0 at the end for strings
saveTo.write(aux_buffer,n);
if (rs->good()){
rs->read(aux_buffer, 1024);
n = rs->gcount();
}
else n = 0;
}
return ofHttpResponse(request,res.getStatus(),res.getReason());
}
} catch (const Exception& exc) {
ofLogError("ofURLFileLoader") << "handleRequest(): "+ exc.displayText();
return ofHttpResponse(request,-1,exc.displayText());
} catch (...) {
return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
}
return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
}
示例2: main
int main(int argc, char **argv) {
// using `web` as provider
URI uri("https://yboss.yahooapis.com/ysearch/web?q=cat");
// init the creds, I think the empty token and token secret are important
OAuth10Credentials creds(
"dj0yJmk9eGx5RzFQOVAwcDZpJmQ9WVdrOWVVUkhWamhwTkdVbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD0wYw--",
"2bf8a4682c4948fb4f7add9598eef5f86b57cf93", "", "");
HTTPRequest request(HTTPRequest::HTTP_GET, uri.getPathEtc());
// put the `q` as param
HTMLForm params;
params.set("q", "cat");
creds.authenticate(request, uri, params);
std::string auth = request.get("Authorization");
std::cout << auth << std::endl;
const Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
session.sendRequest(request);
HTTPResponse response;
std::istream& rs = session.receiveResponse(response);
std::cout << response.getStatus() << " " << response.getReason() << std::endl;
StreamCopier::copyStream(rs, std::cout);
return 0;
}
示例3: main
int main(int argc, char** argv)
{
if (argc != 2)
{
Path p(argv[0]);
std::cout << "usage: " << p.getBaseName() << " <uri>" << std::endl;
std::cout << " fetches the resource identified by <uri> and print it to the standard output" << std::endl;
return 1;
}
try
{
URI uri(argv[1]);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
std::cout << res.getStatus() << " " << res.getReason() << std::endl;
StreamCopier::copyStream(rs, std::cout);
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
示例4: handleRequest
ofHttpResponse ofURLFileLoader::handleRequest(ofHttpRequest request) {
try {
URI uri(request.url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.setTimeout(Poco::Timespan(20,0));
session.sendRequest(req);
HTTPResponse res;
istream& rs = session.receiveResponse(res);
if(!request.saveTo){
return ofHttpResponse(request,rs,res.getStatus(),res.getReason());
}else{
ofFile saveTo(request.name,ofFile::WriteOnly,true);
char aux_buffer[1024];
rs.read(aux_buffer, 1024);
std::streamsize n = rs.gcount();
while (n > 0){
// we resize to size+1 initialized to 0 to have a 0 at the end for strings
saveTo.write(aux_buffer,n);
if (rs){
rs.read(aux_buffer, 1024);
n = rs.gcount();
}
else n = 0;
}
return ofHttpResponse(request,res.getStatus(),res.getReason());
}
} catch (const Exception& exc) {
ofLog(OF_LOG_ERROR, "ofURLFileLoader " + exc.displayText());
return ofHttpResponse(request,-1,exc.displayText());
} catch (...) {
return ofHttpResponse(request,-1,"ofURLFileLoader fatal error, couldn't catch Exception");
}
}
示例5: s
void HTTPResponseTest::testRead1()
{
std::string s("HTTP/1.1 500 Internal Server Error\r\n\r\n");
std::istringstream istr(s);
HTTPResponse response;
response.read(istr);
assert (response.getStatus() == HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
assert (response.getReason() == "Internal Server Error");
assert (response.getVersion() == HTTPMessage::HTTP_1_1);
assert (response.empty());
assert (istr.get() == -1);
}
示例6: POST_request
POCO_HttpClient_response POCO_HttpClient::POST_request(string param_uri)
{
_mutex.lock();
URI uri(param_uri);
string path(uri.getPath());
if (path.empty()) path = "/";
string requestBody = uri.getQuery();
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
HTTPResponse response;
session.setKeepAlive(true);
request.setKeepAlive(true);
request.setContentType("application/x-www-form-urlencoded");
request.setContentLength(requestBody.length());
string state = "";
string reason = "";
string received = "";
HTTPResponse::HTTPStatus status = HTTPResponse::HTTPStatus::HTTP_NOT_FOUND;
try
{
session.sendRequest(request) << requestBody;
std::istream& rs = session.receiveResponse(response);
status = response.getStatus();
reason = response.getReason();
received = "";
string temp;
while (getline(rs, temp))
{
received += temp + "\n";
}
state = "success";
}
catch (NetException e)
{
state = "exception";
received = e.displayText();
}
catch (...)
{
state = "exception";
received = "exception";
}
_mutex.unlock();
return POCO_HttpClient_response(state, received, status, reason);
}
示例7: s
void HTTPResponseTest::testRead3()
{
std::string s("HTTP/1.1 200 \r\nContent-Length: 0\r\n\r\n");
std::istringstream istr(s);
HTTPResponse response;
response.read(istr);
assert (response.getVersion() == HTTPMessage::HTTP_1_1);
assert (response.getStatus() == HTTPResponse::HTTP_OK);
assert (response.getReason() == "");
assert (response.size() == 1);
assert (response.getContentLength() == 0);
assert (istr.get() == -1);
}
示例8: proxyConnect
StreamSocket HTTPClientSession::proxyConnect()
{
HTTPClientSession proxySession(getProxyHost(), getProxyPort());
proxySession.setTimeout(getTimeout());
SocketAddress targetAddress(getHost(), getPort());
HTTPRequest proxyRequest(HTTPRequest::HTTP_CONNECT, targetAddress.toString(), HTTPMessage::HTTP_1_1);
HTTPResponse proxyResponse;
proxyRequest.set("Proxy-Connection", "keep-alive");
proxyRequest.set("Host", getHost());
proxyAuthenticateImpl(proxyRequest);
proxySession.setKeepAlive(true);
proxySession.sendRequest(proxyRequest);
proxySession.receiveResponse(proxyResponse);
if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK)
throw HTTPException("Cannot establish proxy connection", proxyResponse.getReason());
return proxySession.detachSocket();
}
示例9: GET_request
/*
POCO_HttpClient_response POCO_HttpClient::GET_request(string param_uri)
{
URI uri(param_uri);
string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
HTTPResponse response;
session.sendRequest(request);
std::istream& rs = session.receiveResponse(response);
HTTPResponse::HTTPStatus status = response.getStatus();
string reason = response.getReason();
string received = "";
string temp;
while (getline(rs, temp))
{
received += temp + "\n";
}
return POCO_HttpClient_response(received, status, reason);
}
*/
POCO_HttpClient_response POCO_HttpClient::GET_request(string param_uri)
{
_mutex.lock();
URI uri(param_uri);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest request(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
HTTPResponse response;
string state = "";
string reason = "";
string received = "";
HTTPResponse::HTTPStatus status = HTTPResponse::HTTPStatus::HTTP_NOT_FOUND;
try
{
session.sendRequest(request);
std::istream& rs = session.receiveResponse(response);
status = response.getStatus();
reason = response.getReason();
received = "";
string temp;
while (getline(rs, temp))
{
received += temp + "\n";
}
state = "success";
}
catch (NetException e)
{
state = "exception";
received = e.displayText();
}
catch (...)
{
state = "exception";
received = "exception";
}
_mutex.unlock();
return POCO_HttpClient_response(state, received, status, reason);
}
示例10: connect
void HTTPSClientSession::connect(const SocketAddress& address)
{
if (getProxyHost().empty())
{
SecureStreamSocket sss(socket());
if (_pContext->sessionCacheEnabled())
{
sss.useSession(_pSession);
}
HTTPSession::connect(address);
if (_pContext->sessionCacheEnabled())
{
_pSession = sss.currentSession();
}
}
else
{
HTTPClientSession proxySession(address);
proxySession.setHost(getProxyHost());
proxySession.setPort(getProxyPort());
proxySession.setTimeout(getTimeout());
SocketAddress targetAddress(getHost(), getPort());
HTTPRequest proxyRequest(HTTPRequest::HTTP_CONNECT, targetAddress.toString(), HTTPMessage::HTTP_1_1);
HTTPResponse proxyResponse;
proxyRequest.set("Proxy-Connection", "keep-alive");
proxyRequest.set("Host", getHost());
proxyAuthenticateImpl(proxyRequest);
proxySession.setKeepAlive(true);
proxySession.sendRequest(proxyRequest);
proxySession.receiveResponse(proxyResponse);
if (proxyResponse.getStatus() != HTTPResponse::HTTP_OK)
throw HTTPException("Cannot establish proxy connection", proxyResponse.getReason());
StreamSocket proxySocket(proxySession.detachSocket());
SecureStreamSocket secureSocket = SecureStreamSocket::attach(proxySocket, getHost(), _pContext, _pSession);
attachSocket(secureSocket);
if (_pContext->sessionCacheEnabled())
{
_pSession = secureSocket.currentSession();
}
}
}
示例11: handleRequest
ofHttpResponse ofURLFileLoader::handleRequest(ofHttpRequest request) {
try {
URI uri(request.url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.setTimeout(Poco::Timespan(20,0));
session.sendRequest(req);
HTTPResponse res;
istream& rs = session.receiveResponse(res);
return ofHttpResponse(request,rs,res.getStatus(),res.getReason());
} catch (Exception& exc) {
ofLog(OF_LOG_ERROR, "ofURLFileLoader " + exc.displayText());
return ofHttpResponse(request,-1,exc.displayText());
}
}
示例12: handleTextRequest
void SimpleWebScraper::handleTextRequest(string url_) {
try {
URI uri(url_);
string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
std::cout << res.getStatus() << " " << res.getReason() << std::endl;
StreamCopier::copyToString(rs, response);
} catch (Exception& exc) {
cerr << exc.displayText() << std::endl;
}
}
示例13: resourceFile
void OAuthPrivate::resourceFile(const std::string method, const std::string url, const std::string & filename, const std::string status){
std::string authStr = buildAuthHeader(method, url, Params());
authStr = "OAuth " + authStr;
URI uri(url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
const Poco::Net::Context::Ptr context( new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "cacert.pem"));
HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
HTTPRequest request(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
HTTPResponse response;
Poco::Net::HTMLForm form;
form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
form.set("status", status);
form.addPart("media[]", new Poco::Net::FilePartSource(filename, filename, "application/octet-stream"));
form.prepareSubmit(request);
request.set("Authorization", authStr);
std::ostream & ostr = session.sendRequest(request);
form.write(ostr);
std::istream& rs = session.receiveResponse(response);
std::cout << response.getStatus() << " " << response.getReason() << std::endl;
if (response.getStatus() != Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
{
StreamCopier::copyStream(rs, std::cout);
}
else
{
Poco::NullOutputStream null;
StreamCopier::copyStream(rs, null);
}
}
示例14: doUpload
//-------------------------------------------------------------
string API::doUpload( string image ){
if ( !bAuthenticated ){
ofLogWarning( "Not authenticated! Please call authenticate() with proper api key and secret" );
return "";
} else if ( currentPerms != FLICKR_WRITE ){
ofLogWarning( "You do not have proper permissions to upload! Please call authenticate() with permissions of ofxFlickr::FLICKR_WRITE" );
return "";
}
map<string,string> args;
args["api_key"] = api_key;
args["auth_token"] = auth_token;
string result;
FilePartSource * fps = new FilePartSource(image, "image/jpeg");
try
{
// prepare session
const URI uri( "https://" + api_base );
HTTPSClientSession session( uri.getHost(), uri.getPort() );
HTTPRequest req(HTTPRequest::HTTP_POST, "/services/upload/", HTTPMessage::HTTP_1_0);
req.setContentType("multipart/form-data");
// setup form
HTMLForm form;
form.set("api_key", api_key);
form.set("auth_token", auth_token);
form.set("api_sig", apiSig( args ));
form.setEncoding(HTMLForm::ENCODING_MULTIPART);
form.addPart("photo", fps);
form.prepareSubmit(req);
std::ostringstream oszMessage;
form.write(oszMessage);
std::string szMessage = oszMessage.str();
req.setContentLength((int) szMessage.length() );
//session.setKeepAlive(true);
// send form
ostream & out = session.sendRequest(req) << szMessage;
// get response
HTTPResponse res;
cout << res.getStatus() << " " << res.getReason() << endl;
// print response
istream &is = session.receiveResponse(res);
StreamCopier::copyToString(is, result);
}
catch (Exception &ex)
{
cerr << "error? " + ex.displayText() <<endl;
}
string photoid;
ofxXmlSettings xml;
xml.loadFromBuffer(result);
xml.pushTag("rsp");{
photoid = xml.getValue("photoid", "");
}; xml.popTag();
return photoid;
}
示例15: handleRequest
ofHttpResponse ofURLFileLoaderImpl::handleRequest(const ofHttpRequest & request) {
try {
URI uri(request.url);
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
std::string pocoMethod;
if(request.method==ofHttpRequest::GET){
pocoMethod = HTTPRequest::HTTP_GET;
}else{
pocoMethod = HTTPRequest::HTTP_POST;
}
HTTPRequest req(pocoMethod, path, HTTPMessage::HTTP_1_1);
for(map<string,string>::const_iterator it = request.headers.cbegin(); it!=request.headers.cend(); it++){
req.add(it->first,it->second);
}
HTTPResponse res;
std::unique_ptr<HTTPClientSession> session;
if(uri.getScheme()=="https"){
//const Poco::Net::Context::Ptr context( new Poco::Net::Context( Poco::Net::Context::CLIENT_USE, "", "", "rootcert.pem" ) );
session.reset(new HTTPSClientSession(uri.getHost(), uri.getPort()));//,context);
}else{
session.reset(new HTTPClientSession(uri.getHost(), uri.getPort()));
}
session->setTimeout(Poco::Timespan(120,0));
if(request.contentType!=""){
req.setContentType(request.contentType);
}
if(request.body!=""){
req.setContentLength( request.body.length() );
auto & send = session->sendRequest(req);
send.write(request.body.c_str(), request.body.size());
send << std::flush;
}else{
session->sendRequest(req);
}
auto & rs = session->receiveResponse(res);
if(!request.saveTo){
return ofHttpResponse(request,rs,res.getStatus(),res.getReason());
}else{
ofFile saveTo(request.name,ofFile::WriteOnly,true);
char aux_buffer[1024];
rs.read(aux_buffer, 1024);
std::streamsize n = rs.gcount();
while (n > 0){
// we resize to size+1 initialized to 0 to have a 0 at the end for strings
saveTo.write(aux_buffer,n);
if (rs.good()){
rs.read(aux_buffer, 1024);
n = rs.gcount();
}
else n = 0;
}
return ofHttpResponse(request,res.getStatus(),res.getReason());
}
} catch (const Exception& exc) {
ofLogError("ofURLFileLoader") << "handleRequest(): "+ exc.displayText();
return ofHttpResponse(request,-1,exc.displayText());
} catch (...) {
return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
}
return ofHttpResponse(request,-1,"ofURLFileLoader: fatal error, couldn't catch Exception");
}