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


C++ HTTPResponse::write方法代码示例

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


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

示例1:

void HTTPResponseTest::testWrite1()
{
	HTTPResponse response;
	std::ostringstream ostr;
	response.write(ostr);
	std::string s = ostr.str();
	assert (s == "HTTP/1.0 200 OK\r\n\r\n");
}
开发者ID:,项目名称:,代码行数:8,代码来源:

示例2: makeRequest

void DataSender::makeRequest() {
	HTTPClientSession session(_address);
	//s.setProxy("localhost", srv.port());
	HTTPRequest request(HTTPRequest::HTTP_POST, "/TSPResults.json"); // This will have to change
	request.setContentType("application/json");
	request.setKeepAlive(true);

	session.sendRequest(request) << generateRequestPOSTString();

	HTTPResponse response;
	std::istream& rs = session.receiveResponse(response);

	// Output the HTTP response message and the content of the message
	response.write(cout) ;
	Poco::StreamCopier::copyStream(rs, cout);
}
开发者ID:ElectricAegis,项目名称:WitsTSPCluster,代码行数:16,代码来源:DataSender.cpp

示例3: authHeader

SwiftResult<T>* doSwiftTransaction(Account *_account, std::string &_uriPath,
    const std::string &_method, std::vector<HTTPHeader>* _uriParams,
    std::vector<HTTPHeader>* _reqMap, std::vector<int> *_httpValidCodes,
    const char *bodyReqBuffer, ulong size, std::string *contentType) {
  //Start locking
  lock_guard<recursive_mutex> guard(transactionMutex);
  //Start of function
  if (_account == nullptr)
    return returnNullError<T>("account");
  Endpoint* swiftEndpoint = _account->getSwiftService()->getFirstEndpoint();
  if (swiftEndpoint == nullptr)
    return returnNullError<T>("SWIFT Endpoint");

  //Create parameter map
  vector<HTTPHeader> reqParamMap;
  //Add authentication token
  string tokenID = _account->getToken()->getId();
  HTTPHeader authHeader("X-Auth-Token", tokenID);
  reqParamMap.push_back(authHeader);
  //Add rest of request Parameters
  if (_reqMap != nullptr && _reqMap->size() > 0) {
    for (uint i = 0; i < _reqMap->size(); i++) {
      reqParamMap.push_back(_reqMap->at(i));
    }
  }

  URI uri(swiftEndpoint->getPublicUrl());
  string encoded;
  URI::encode(_uriPath,"",encoded);
  _uriPath = encoded;
  if (uri.getPath().size() > 0)
    uri.setPath(uri.getPath() + "/" + _uriPath);
  else
    uri.setPath(_uriPath);

  if (_uriParams != nullptr && _uriParams->size() > 0) {
    //Create appropriate URI
    ostringstream queryStream;
    //queryStream << "?";
    for (uint i = 0; i < _uriParams->size(); i++) {
      if (i > 0)
        queryStream << ",";
      queryStream << _uriParams->at(i).getQueryValue();
    }
    uri.setQuery(queryStream.str());
  }

  //Creating HTTP Session
  HTTPResponse *httpResponse = new HTTPResponse();
  HTTPClientSession *httpSession = nullptr;
  istream* resultStream = nullptr;

  try {
    /** This operation does not accept a request body. **/
    if (bodyReqBuffer == nullptr)
      httpSession = doHTTPIO(uri, _method, &reqParamMap);
    else {
      if (contentType != nullptr)
        httpSession = doHTTPIO(uri, _method, &reqParamMap, bodyReqBuffer, size,
            *contentType);
      else
        httpSession = doHTTPIO(uri, _method, &reqParamMap, bodyReqBuffer, size,"");
    }

    //Now we should increase number of calls to SWIFT API
    _account->increaseCallCounter();
    if (std::is_same<T, std::istream*>::value)
      resultStream = &httpSession->receiveResponse(*httpResponse);
    else
    	httpSession->receiveResponse(*httpResponse);
  } catch (Exception &e) {
    SwiftResult<T> *result = new SwiftResult<T>();
    SwiftError error(SwiftError::SWIFT_EXCEPTION, e.displayText());
    result->setError(error);
    //Try to set HTTP Response as the payload
    result->setSession(httpSession);
    result->setResponse(httpResponse);
    result->setPayload(nullptr);
    return result;
  }

  /**
   * Check HTTP return code
   */
  bool valid = false;
  for (uint i = 0; i < _httpValidCodes->size(); i++)
    if (_httpValidCodes->at(i) == httpResponse->getStatus()) {
      valid = true;
      break;
    }

  if (!valid) {
  	cout<<"Invalid Return code:";
    httpResponse->write(cout);
    if(httpResponse->getStatus() == 200)
    	cerr<<"bullshit"<<endl;
    if(httpResponse->getStatus() == HTTPResponse::HTTP_UNAUTHORIZED) {
      if(_account->reAuthenticate()) {
        delete httpSession;httpSession = nullptr;
        delete httpResponse;httpResponse = nullptr;
//.........这里部分代码省略.........
开发者ID:RobinSystems,项目名称:Swift_CPP_SDK,代码行数:101,代码来源:HTTPIO.cpp

示例4: main

int main(int argc, char** argv) {
  AuthenticationInfo info;
  info.username = "behrooz";
  info.password = "behrooz";
  info.authUrl = "http://10.42.0.83:5000/v2.0/tokens";
  info.tenantName = "kos";
  info.method = AuthenticationMethod::KEYSTONE;

  //Account Test cases
  SwiftResult<Account*>* authenticateResult = Account::authenticate(info);
  cout << "Account Test case:\n" << authenticateResult->getPayload()->toString()
      << endl << endl;

  //Get account details
  SwiftResult<istream*>* accountDetails =
      authenticateResult->getPayload()->swiftAccountDetails(
          HEADER_FORMAT_APPLICATION_JSON);
  StreamCopier::copyStream(*accountDetails->getPayload(), cout);
  cout << endl << endl;
  delete accountDetails;

  //Create account metadata
  vector<pair<string, string> > accountMetaData;
  accountMetaData.push_back(make_pair("Key1", "Value1"));
  //accountMetaData.push_back(make_pair("Key 2", "Value 2"));
  SwiftResult<int*>* accountMetaDataRes =
      authenticateResult->getPayload()->swiftCreateMetadata(accountMetaData);
  accountMetaDataRes->getResponse()->write(cout);
  cout << endl << endl;
  delete accountMetaDataRes;

  //Show account metadata
	accountMetaDataRes = authenticateResult->getPayload()->swiftShowMetadata();
	accountMetaDataRes->getResponse()->write(cout);
	cout << endl << endl;
	delete accountMetaDataRes;

  //delete account metadata
  vector<string> accountMetaDataDeleteKeys;
  accountMetaDataDeleteKeys.push_back("Key 2");
  accountMetaDataRes = authenticateResult->getPayload()->swiftDeleteMetadata(
      accountMetaDataDeleteKeys);
  accountMetaDataRes->getResponse()->write(cout);
  cout << endl << endl;
  delete accountMetaDataRes;

  //Update account metadata
  accountMetaData.clear();
  accountMetaData.push_back(make_pair("Key 1", "Value 1 updated"));
  accountMetaDataRes = authenticateResult->getPayload()->swiftUpdateMetadata(
      accountMetaData);
  accountMetaDataRes->getResponse()->write(cout);
  cout << endl << endl;
  delete accountMetaDataRes;

  //Show account metadata
  accountMetaDataRes = authenticateResult->getPayload()->swiftShowMetadata();
  accountMetaDataRes->getResponse()->write(cout);
  cout << endl << endl;
  delete accountMetaDataRes;

  //List containers
  SwiftResult<vector<Container>*>* containerListRes = authenticateResult->getPayload()->swiftGetContainers();
  cout<<"Num of Container:"<<containerListRes->getPayload()->size()<<endl;;
  if(containerListRes->getError().code == SWIFT_OK.code)
    for(auto it=containerListRes->getPayload()->begin();it!=containerListRes->getPayload()->end();++it)
      cout<<"Container:"<<(*it).getName()<<endl;
  cout<<endl;
  delete containerListRes;

  //Container Test Cases
  Container container(authenticateResult->getPayload(), "Container2");

  //Create container
  SwiftResult<int*>* containerRes = container.swiftCreateContainer();
  containerRes->getResponse()->write(cout);
  cout << endl << endl;
  delete containerRes;

  //Container list objects test
  Container container2(authenticateResult->getPayload(), "Container2");
  SwiftResult<vector<Object>*>* objects = container2.swiftGetObjects(true);
  if(objects->getError().code == SwiftError::SWIFT_OK)
    for (uint i = 0; i < objects->getPayload()->size(); i++) {
      cout << objects->getPayload()->at(i).getName() << "\tLength:"
          << objects->getPayload()->at(i).getLength() << "\tType:"
          << objects->getPayload()->at(i).getContentType() << "\tHash:"
          << objects->getPayload()->at(i).getHash() << "\tLastModiefied:"
          << objects->getPayload()->at(i).getLastModified() << endl;
    }
  delete objects;

  //Delete container
  containerRes = container.swiftDeleteContainer();
  containerRes->getResponse()->write(cout);
  cout << endl << endl;
  delete containerRes;

  //Create Again
  SwiftResult<int*>*createRes = container.swiftCreateContainer();
//.........这里部分代码省略.........
开发者ID:RobinSystems,项目名称:Swift_CPP_SDK,代码行数:101,代码来源:test.cpp


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