コード例 #1
0
ファイル: evisimagedisplaywidget.cpp プロジェクト: Ariki/QGIS
/**
* Public method called to display an image loaded from a url
* @param url - The url from which to load an image
*/
void eVisImageDisplayWidget::displayUrlImage( QString url )
{
  QUrl myUrl( url );
#if QT_VERSION < 0x050000
  mHttpConnection->setHost( myUrl.host() );
  mCurrentHttpImageRequestId = mHttpConnection->get( myUrl.path().replace( "\\", "/" ), mHttpBuffer );
#endif
}
コード例 #2
0
ファイル: example01.cpp プロジェクト: Chronodt/curlpp
/** 
 * This example is made to show you how you can use the Options.
 */
int main(int, char **)
{
	try
	{
		curlpp::Cleanup myCleanup;

		// First easy example.
		{
		  // The first easiest example is to retreive the content of
		  // a web page and put it in a stream.
		  std::cout << curlpp::options::Url("http://example.com");

		  // You don't need to use just the standard outputs. You
		  // can use any stream:
		  std::ostringstream os;
		  os << curlpp::options::Url("http://example.com");
		}

		// More elaborate example.
		{
		  // What the previous example done there was simply 
		  // to create a curlpp::Easy class, which is the basic
		  // object in cURLpp, and then set the Url option.
		  // curlpp::options classes are the primitives that allow to specify 
		  // values to the requests. 
		  curlpp::options::Url myUrl(std::string("http://example.com"));
		  curlpp::Easy myRequest;
		  myRequest.setOpt(myUrl);

		  // Now that all the options we wanted to set are there, we need to
		  // actually do the request. the "perform" method does actually that.
		  // With that call, the request will be done and the content of that URL
		  // will be printed in std::cout (which is the default).
		  myRequest.perform();

		  // If we wanted to put the content of the URL within a string stream
		  // (or any type of std::ostream, for that matter), like the first example, 
		  // we would use the WriteStrem option like this:
		  std::ostringstream os;
		  curlpp::options::WriteStream ws(&os);
		  myRequest.setOpt(ws);
		  myRequest.perform();

		  // There is some shorcut within curlpp that allow you to write shorter code
		  // like this:
		  os << myRequest;

		  // That would do exactly what the previous code was doing.
		}

		// Creation of the URL option.
		curlpp::options::Url myUrl(std::string("http://example.com"));

		// Copy construct from the other URL.
		curlpp::options::Url myUrl2(myUrl);

		// Creation of the port option.
		curlpp::options::Port myPort(MyPort);

		// Creation of the request.
		curlpp::Easy myRequest;

		// Creation of an option that contain a copy of the URL option.
		curlpp::OptionBase *mytest = myUrl.clone();
		myRequest.setOpt(*mytest);

		// You can reuse the base option for other type of option
		// and set the option to the request. but first, don't forget 
		// to delete the previous memory. You can delete it since the 
		// option is internally duplicated for the request.
		delete mytest;
		mytest = myPort.clone();
		myRequest.setOpt(*mytest);
		delete mytest;

		// You can clone an option directly to the same type of 
		// option.
		curlpp::options::Url *myUrl3 = myUrl.clone();
		myRequest.setOpt(myUrl3);
		// Now myUrl3 is owned by the request we will NOT use 
		// it anymore.


		// You don't need to declare an option if you just want 
		// to use it once.
		myRequest.setOpt(curlpp::options::Url("example.com"));


		// Note that the previous line wasn't really efficient
		// because we create the option, this option is duplicated
		// for the request and then the option destructor is called.
		// You can use this instead:
		myRequest.setOpt(new curlpp::options::Url("example.com"));
		// Note that with this the request will use directly this
		// instance we just created. Be aware that if you pass an
		// Option pointer to the setOpt function, it will consider
		// the instance has its own instance. The Option instance
		// will be deleted when the request will be deleted, so
		// don't use the instance further in your code.


		// Doing the previous line is efficient as this:
		myRequest.setOpt(myUrl.clone());


		// You can retreive the value of a specific option.
		std::cout << myUrl2.getValue() << std::endl;

		// Perform the transaction with the options set.
		myRequest.perform();
	}

	catch( curlpp::RuntimeError &e )
	{
		std::cout << e.what() << std::endl;
	}

	catch( curlpp::LogicError &e )
	{
		std::cout << e.what() << std::endl;
	}
    
  return 0;
}
コード例 #3
0
ファイル: example01.cpp プロジェクト: blog2i2j/greentimer
/** 
 * This example is made to show you how you can use the Options.
 */
int main(int, char **)
{
  try
    {
      cURLpp::Cleanup myCleanup;

      // Creation of the URL option.
      cURLpp::Options::Url myUrl(std::string("http://example.com"));
      
      // Copy construct from the other URL.
      cURLpp::Options::Url myUrl2(myUrl);

      // Creation of the port option.
      cURLpp::Options::Port myPort(MY_PORT);

      // Creation of the request.
      cURLpp::Easy myRequest;


      // Creation of an option that contain a copy of the URL option.
      cURLpp::OptionBase *mytest = myUrl.clone();
      myRequest.setOpt(*mytest);

      // You can reuse the base option for other type of option
      // and set the option to the request. but first, don't forget 
      // to delete the previous memory. You can delete it since the 
      // option is internally duplicated for the request.
      delete mytest;
      mytest = myPort.clone();
      myRequest.setOpt(*mytest);
      delete mytest;

      // You can clone an option directly to the same type of 
      // option.
      cURLpp::Options::Url *myUrl3 = myUrl.clone();
      myRequest.setOpt(myUrl3);
      // Now myUrl3 is owned by the request we will NOT use 
      // it anymore.


      // You don't need to declare an option if you just want 
      // to use it once.
      myRequest.setOpt(cURLpp::Options::Url("example.com"));
      

      // Note that the previous line wasn't really efficient
      // because we create the option, this option is duplicated
      // for the request and then the option destructor is called.
      // You can use this instead:
      myRequest.setOpt(new cURLpp::Options::Url("example.com"));
      // Note that with this the request will use directly this
      // instance we just created. Be aware that if you pass an
      // Option pointer to the setOpt function, it will consider
      // the instance has its own instance. The Option instance
      // will be deleted when the request will be deleted, so
      // don't use the instance further in your code.


      // Doing the previous line is efficient as this:
      myRequest.setOpt(myUrl.clone());

      
      // You can retreive the value of a specific option.
      std::cout << myUrl2.getValue() << std::endl;

      // Perform the transaction with the options set.
      myRequest.perform();
    }
  catch( cURLpp::RuntimeError &e )
    {
      std::cout << e.what() << std::endl;
    }
  catch( cURLpp::LogicError &e )
    {
      std::cout << e.what() << std::endl;
    }
    
  return 0;
}
コード例 #4
0
ファイル: api.cpp プロジェクト: oncaphillis/tmdbpp
    std::string Api::fetch(const std::string & url) {
        int retry = 0;
        while (retry++ < 3) {
            try {
                _status = ErrorStatus();
                int code;
                std::string content;
#ifdef _WIN32
                WGet::Result r = WGet::instance().get(url);
                code = r.code;
                content = r.content;
#else
                std::stringstream ss;
                curlpp::options::Url myUrl(url);
                curlpp::Easy myRequest;

                myRequest.setOpt(myUrl);
                myRequest.setOpt(curlpp::options::WriteStream(&ss));
                myRequest.setOpt(curlpp::options::FailOnError(false));

                myRequest.perform();

                curlpp::InfoGetter::get(myRequest,CURLINFO_RESPONSE_CODE,code);

                content = ss.str();
#endif
                if (code != 200) {

                    // Gateway timeout.. wait and try again max 3 times
                    if (code == 504) {
#ifdef _WIN32
                        ::Sleep(retry * 1000);
#else
                        ::sleep(retry);
#endif
                        continue;
                    }

                    if (!content.empty()) {
                        _status = ErrorStatus(content);
                    }

                    if (code == 404 && !content.empty() && _status.status_code() == Api::StatusCode::StatusInvalidId) {
                        return "";
                    }
                    if (code == 401 && !content.empty() && _status.status_code() == Api::StatusCode::StatusDenied) {
                        return "";
                    }
                    if (code == 401 && !content.empty() && _status.status_code() == Api::StatusCode::StatusInvalidLogin) {
                        return "";
                    }

                    std::stringstream ss;

                    ss << "code #" << code << " status_message '" << _status.status_message() << "' "
                        << " status code='" << _status.status_code() << "'"
                        << " on URL '" << url << "'" << std::endl;

                    throw std::runtime_error(ss.str());
                }
                return content;
            }
            catch (std::exception ex) {
                throw;
            }
        }
    }