当前位置: 首页>>代码示例>>C++>>正文


C++ URI::getPort方法代码示例

本文整理汇总了C++中URI::getPort方法的典型用法代码示例。如果您正苦于以下问题:C++ URI::getPort方法的具体用法?C++ URI::getPort怎么用?C++ URI::getPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在URI的用法示例。


在下文中一共展示了URI::getPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bev

Connection::Connection(cb::Event::Base &base, DNSBase &dns, const URI &uri,
                       const SmartPointer<SSLContext> &sslCtx) :
  con(0), deallocate(true) {
  bool https = uri.getScheme() == "https";

#ifdef HAVE_OPENSSL
  if (https && sslCtx.isNull()) THROW("Need SSL context for https connection");

  BufferEvent bev(base, https ? sslCtx : 0, uri.getHost());
#else

  if (https) THROW("C! not built with OpenSSL support");

  BufferEvent bev(base, 0, uri.getHost());
#endif

  // TODO OpenSSL connections do not work with async DNS
  con = evhttp_connection_base_bufferevent_new
    (base.getBase(), sslCtx.isNull() ? dns.getDNSBase() : 0, bev.adopt(),
     uri.getHost().c_str(), uri.getPort());

  LOG_DEBUG(5, "Connecting to " << uri.getHost() << ':' << uri.getPort());

  if (!con) THROWS("Failed to create connection to " << uri);
}
开发者ID:kbernhagen,项目名称:cbang,代码行数:25,代码来源:Connection.cpp

示例2: Message

Request::Request(RequestMethod method, const URI &uri, float version) :
  Message(version), method(method), uri(uri) {
  if (version != 1.0) {
    set("Host", uri.getHost());
    if ((uri.getScheme() == "http" && uri.getPort() != 80) ||
        (uri.getScheme() == "https" && uri.getPort() != 443))
      append("Host", String(uri.getPort()));
  }
}
开发者ID:trasz,项目名称:cbang,代码行数:9,代码来源:Request.cpp

示例3: ShouldBypass

	bool Proxy::ShouldBypass(URI& uri)
	{
		const std::string& uriHost = uri.getHost();
		const std::string& uriScheme = uri.getScheme();
		unsigned short uriPort = uri.getPort();
		for (size_t i = 0; i < bypassList.size(); i++)
		{
			SharedURI entry = bypassList.at(i);

			// An empty bypass entry equals an unconditional bypass.
			if (entry.isNull())
			{
				return true;
			}
			else
			{
				const std::string& entryHost = entry->getHost();
				const std::string& entryScheme = entry->getScheme();
				unsigned short entryPort = entry->getPort();

				if (entryHost == "<local>" && uriHost.find(".") == string::npos)
				{
					return true;
				}
				else if (EndsWith(uriHost, entryHost) &&
					(entryScheme.empty() || entryScheme == uriScheme) &&
					(entryPort == 0 || entryPort == uriPort))
				{
					return true;
				}
			}
		}

		return false;
	}
开发者ID:jonnymind,项目名称:kroll,代码行数:35,代码来源:proxy_config.cpp

示例4: ShouldBypassWithEntry

static bool ShouldBypassWithEntry(URI& uri, SharedPtr<BypassEntry> entry)
{
    const std::string& uriHost = uri.getHost();
    const std::string& uriScheme = uri.getScheme();
    unsigned short uriPort = uri.getPort();
    const std::string& entryHost = entry->host;
    const std::string& entryScheme = entry->scheme;
    unsigned short entryPort = entry->port;

    GetLogger()->Debug("bypass entry: scheme='%s' host='%s' port='%i'",
                       entry->scheme.c_str(), entry->host.c_str(), entry->port);

    // An empty bypass entry equals an unconditional bypass.
    if (entry.isNull())
    {
        return true;
    }
    else
    {
        if (entryHost == "<local>" && uriHost.find(".") == string::npos)
        {
            return true;
        }
        else if (EndsWith(uriHost, entryHost) &&
                 (entryScheme.empty() || entryScheme == uriScheme) &&
                 (entryPort == 0 || entryPort == uriPort))
        {
            return true;
        }
    }

    return false;
}
开发者ID:toisoftware,项目名称:TideSDK,代码行数:33,代码来源:proxy_config.cpp

示例5: get

void Transaction::get(const URI &uri, float version) {
  if (!isConnected()) connect(IPAddress(uri.getHost(), uri.getPort()));

  Request request(RequestMethod::HTTP_GET, resolve(uri), version);
  request.setPersistent(false);
  ProxyManager::instance().addCredentials(request);

  send(request);
}
开发者ID:trasz,项目名称:cbang,代码行数:9,代码来源:Transaction.cpp

示例6: equals

bool URI::equals(const URI& uri) const
{
	return _scheme   == uri._scheme
	    && _userInfo == uri._userInfo
	    && _host     == uri._host
	    && getPort() == uri.getPort()
	    && _path     == uri._path
	    && _query    == uri._query
	    && _fragment == uri._fragment;
}
开发者ID:Victorcasas,项目名称:georest,代码行数:10,代码来源:URI.cpp

示例7: mMethod

HttpRequest::HttpRequest( const URI &uri, MethodType type ) :
      mMethod( type ), mUri( uri ) {
   char buf[16];
   snprintf( buf, 15, "%d", uri.getPort() );
   std::string host = uri.getHost();
   host += ":";
   host += buf;

   addField( HttpFieldMap::kFieldHost, host.c_str() );
   addDateField();
}
开发者ID:lmtan91,项目名称:common,代码行数:11,代码来源:HttpRequest.cpp

示例8: resolve

URI Transaction::resolve(const URI &_uri) {
  URI uri = _uri;

  if (uri.getHost().empty()) {
    uri.setHost(address.getHost());
    if (uri.getScheme().empty()) uri.setScheme("http");
    if (!uri.getPort()) uri.setPort(address.getPort());
  }

  return uri;
}
开发者ID:trasz,项目名称:cbang,代码行数:11,代码来源:Transaction.cpp

示例9: getString

string Transaction::getString(const URI &uri,
                              SmartPointer<TransferCallback> callback) {
  ostringstream str;
  IPAddress ip(uri.getHost(), uri.getPort());

  connect(ip);
  get(uri);
  download(str, receiveHeader(), callback);

  return str.str();
}
开发者ID:trasz,项目名称:cbang,代码行数:11,代码来源:Transaction.cpp

示例10: post

void Transaction::post(const URI &uri, const char *data, unsigned length,
                       const string &contentType, float version) {
  if (!isConnected()) connect(IPAddress(uri.getHost(), uri.getPort()));

  Request request(RequestMethod::HTTP_POST, resolve(uri), version);
  request.set("Content-Length", String(length));
  request.set("Content-Type", contentType);
  request.setPersistent(false);
  ProxyManager::instance().addCredentials(request);

  send(request);

  if (data) {write(data, length); flush();}
}
开发者ID:trasz,项目名称:cbang,代码行数:14,代码来源:Transaction.cpp

示例11: 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;
    }
开发者ID:robotconscience,项目名称:ofxFlickr,代码行数:70,代码来源:ofxFlickr.cpp

示例12: testConstruction

void URITest::testConstruction()
{
	URI uri;
	assert (uri.getScheme().empty());
	assert (uri.getAuthority().empty());
	assert (uri.getUserInfo().empty());
	assert (uri.getHost().empty());
	assert (uri.getPort() == 0);
	assert (uri.getPath().empty());
	assert (uri.getQuery().empty());
	assert (uri.getFragment().empty());
	
	uri.setScheme("ftp");
	assert (uri.getScheme() == "ftp");
	assert (uri.getPort() == 21);
	
	uri.setScheme("HTTP");
	assert (uri.getScheme() == "http");
	
	uri.setAuthority("www.appinf.com");
	assert (uri.getAuthority() == "www.appinf.com");
	assert (uri.getPort() == 80);
	
	uri.setAuthority("[email protected]:8000");
	assert (uri.getUserInfo() == "user");
	assert (uri.getHost() == "services.appinf.com");
	assert (uri.getPort() == 8000);
	
	uri.setPath("/index.html");
	assert (uri.getPath() == "/index.html");
	
	uri.setPath("/file%20with%20spaces.html");
	assert (uri.getPath() == "/file with spaces.html");
	
	uri.setPathEtc("/query.cgi?query=foo");
	assert (uri.getPath() == "/query.cgi");
	assert (uri.getQuery() == "query=foo");
	assert (uri.getFragment().empty());
	assert (uri.getPathEtc() == "/query.cgi?query=foo");
	assert (uri.getPathAndQuery() == "/query.cgi?query=foo");
	
	uri.setPathEtc("/query.cgi?query=bar#frag");
	assert (uri.getPath() == "/query.cgi");
	assert (uri.getQuery() == "query=bar");
	assert (uri.getFragment() == "frag");
	assert (uri.getPathEtc() == "/query.cgi?query=bar#frag");
	assert (uri.getPathAndQuery() == "/query.cgi?query=bar");
	
	uri.setQuery("query=test");
	assert (uri.getQuery() == "query=test");
	
	uri.setFragment("result");
	assert (uri.getFragment() == "result");
	
	URI uri2("file", "/home/guenter/foo.bar");
	assert (uri2.getScheme() == "file");
	assert (uri2.getPath() == "/home/guenter/foo.bar");
	
	URI uri3("http", "www.appinf.com", "/index.html");
	assert (uri3.getScheme() == "http");
	assert (uri3.getAuthority() == "www.appinf.com");
	assert (uri3.getPath() == "/index.html");
	
	URI uri4("http", "www.appinf.com:8000", "/index.html");
	assert (uri4.getScheme() == "http");
	assert (uri4.getAuthority() == "www.appinf.com:8000");
	assert (uri4.getPath() == "/index.html");

	URI uri5("http", "[email protected]:8000", "/index.html");
	assert (uri5.getScheme() == "http");
	assert (uri5.getUserInfo() == "user");
	assert (uri5.getHost() == "www.appinf.com");
	assert (uri5.getPort() == 8000);
	assert (uri5.getAuthority() == "[email protected]:8000");
	assert (uri5.getPath() == "/index.html");

	URI uri6("http", "[email protected]:80", "/index.html");
	assert (uri6.getScheme() == "http");
	assert (uri6.getUserInfo() == "user");
	assert (uri6.getHost() == "www.appinf.com");
	assert (uri6.getPort() == 80);
	assert (uri6.getAuthority() == "[email protected]");
	assert (uri6.getPath() == "/index.html");

	URI uri7("http", "[email protected]:", "/index.html");
	assert (uri7.getScheme() == "http");
	assert (uri7.getUserInfo() == "user");
	assert (uri7.getHost() == "www.appinf.com");
	assert (uri7.getPort() == 80);
	assert (uri7.getAuthority() == "[email protected]");
	assert (uri7.getPath() == "/index.html");
	
	URI uri8("http", "www.appinf.com", "/index.html", "query=test");
	assert (uri8.getScheme() == "http");
	assert (uri8.getAuthority() == "www.appinf.com");
	assert (uri8.getPath() == "/index.html");
	assert (uri8.getQuery() == "query=test");

	URI uri9("http", "www.appinf.com", "/index.html", "query=test", "fragment");
	assert (uri9.getScheme() == "http");
//.........这里部分代码省略.........
开发者ID:Alcibiades586,项目名称:roadrunner,代码行数:101,代码来源:URITest.cpp

示例13: main

int main( int argc, char*argv[] ) {
   LOG_NOTICE( "Test Started" );

   URI u;

   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );

   string ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );

   for (uint32_t i = 0; i < ARRAY_SIZE( test_urls ); i++) {
      bool res = u.setString( test_urls[i] );

#ifdef DEBUG_PRINTS
      cout << "scheme: " << u.getScheme() << endl;
      cout << "authority: " << u.getAuthority() << endl;
      cout << "host: " << u.getHost() << endl;
      cout << "port: " << u.getPort() << endl;
      cout << "query: " << u.getQuery() << endl;
      cout << "path: " << u.getPath() << endl;
      cout << "fragment: " << u.getFragment() << endl;
      cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
      cout << "query param \"e\": " << u.getQueryParam( "e" ) << endl;
      cout << "is relative: " << u.isRelative() << endl;
#endif

      if ( not res ) {
         LOG_WARN( "parse uri %s: FAILED", test_urls[i] );
         exit( 1 );
      } else {
         LOG_NOTICE( "parse uri %s: PASSED", test_urls[ i ] );
      }
   }

   u.clear();
   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );
   u.appendQueryParam( "a", "b" );
   u.appendQueryParam( "c", "d" );
   u.setFragment( "m" );

   URI copy = u;

   ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );
   ustr = copy.getString();
   LOG_NOTICE( "Copy is: %s", ustr.c_str() );

#ifdef DEBUG_PRINTS
   cout << "scheme: " << u.getScheme() << endl;
   cout << "scheme: " << copy.getScheme() << endl;
   cout << "authority: " << u.getAuthority() << endl;
   cout << "authority: " << copy.getAuthority() << endl;
   cout << "host: " << u.getHost() << endl;
   cout << "host: " << copy.getHost() << endl;
   cout << "port: " << u.getPort() << endl;
   cout << "port: " << copy.getPort() << endl;
   cout << "query: " << u.getQuery() << endl;
   cout << "query: " << copy.getQuery() << endl;
   cout << "path: " << u.getPath() << endl;
   cout << "path: " << copy.getPath() << endl;
   cout << "fragment: " << u.getFragment() << endl;
   cout << "fragment: " << copy.getFragment() << endl;
   cout << "query param \"a\": " << u.getQueryParam( "a" ) << endl;
   cout << "query param \"a\": " << copy.getQueryParam( "a" ) << endl;
   cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
   cout << "query param \"c\": " << copy.getQueryParam( "c" ) << endl;
   cout << "is relative: " << u.isRelative() << endl;
   cout << "is relative: " << copy.isRelative() << endl;
#endif

   if ( u.getScheme() != copy.getScheme()
         or u.getAuthority() != copy.getAuthority()
         or u.getQuery() != copy.getQuery() or u.getPath() != copy.getPath()
         or u.getFragment() != copy.getFragment()
         or u.getQueryParam( "a" ) != copy.getQueryParam( "a" )
         or u.getQueryParam( "c" ) != copy.getQueryParam( "c" )
         or u.isRelative() != copy.isRelative() ) {
      LOG_WARN( "copy of uri: FAILED" );
   } else {
      LOG_NOTICE( "copy of uri: PASSED" );
   }

   return 0;
}
开发者ID:lmtan91,项目名称:common,代码行数:88,代码来源:URITest.cpp

示例14: open

std::istream* HTTPStreamFactory::open(const URI& uri)
{
	poco_assert (uri.getScheme() == "http");

	URI resolvedURI(uri);
	URI proxyUri;
	HTTPClientSession* pSession = 0;
	HTTPResponse res;
	bool retry = false;
	bool authorize = false;
	std::string username;
	std::string password;

	try
	{
		do
		{
			if (!pSession)
			{
				pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
			
				if (proxyUri.empty())
					pSession->setProxy(_proxyHost, _proxyPort);
				else
					pSession->setProxy(proxyUri.getHost(), proxyUri.getPort());
				pSession->setProxyCredentials(_proxyUsername, _proxyPassword);
			}
						
			std::string path = resolvedURI.getPathAndQuery();
			if (path.empty()) path = "/";
			HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
			
			if (authorize)
			{
				HTTPCredentials::extractCredentials(uri, username, password);
				HTTPCredentials cred(username, password);
				cred.authenticate(req, res);
			}
			
			pSession->sendRequest(req);
			std::istream& rs = pSession->receiveResponse(res);
			bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY || 
						  res.getStatus() == HTTPResponse::HTTP_FOUND || 
						  res.getStatus() == HTTPResponse::HTTP_SEE_OTHER ||
						  res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
			if (moved)
			{
				resolvedURI.resolve(res.get("Location"));
				if (!username.empty())
				{
					resolvedURI.setUserInfo(username + ":" + password);
				}
				throw URIRedirection(resolvedURI.toString());
			}
			else if (res.getStatus() == HTTPResponse::HTTP_OK)
			{
				return new HTTPResponseStream(rs, pSession);
			}
			else if (res.getStatus() == HTTPResponse::HTTP_USEPROXY && !retry)
			{
				// The requested resource MUST be accessed through the proxy 
				// given by the Location field. The Location field gives the 
				// URI of the proxy. The recipient is expected to repeat this 
				// single request via the proxy. 305 responses MUST only be generated by origin servers.
				// only use for one single request!
				proxyUri.resolve(res.get("Location"));
				delete pSession; pSession = 0;
				retry = true; // only allow useproxy once
			}
			else if (res.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED && !authorize)
			{
				authorize = true;
				retry = true;
				Poco::NullOutputStream null;
				Poco::StreamCopier::copyStream(rs, null);
			}
			else throw HTTPException(res.getReason(), uri.toString());
		}
		while (retry);
		throw HTTPException("Too many redirects", uri.toString());
	}
	catch (...)
	{
		delete pSession;
		throw;
	}
}
开发者ID:Adoni,项目名称:WiEngine,代码行数:87,代码来源:HTTPStreamFactory.cpp

示例15: req

Request::Request(evhttp_request *req, const URI &uri, bool deallocate) :
  req(req), deallocate(deallocate), originalURI(uri), uri(uri),
  clientIP(uri.getHost(), uri.getPort()), incoming(false), secure(false),
  finalized(false) {
  if (!req) THROW("Event request cannot be null");
}
开发者ID:kbernhagen,项目名称:cbang,代码行数:6,代码来源:Request.cpp


注:本文中的URI::getPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。