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


C++ HttpResponse::getData方法代码示例

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


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

示例1: receiveRequest

void receiveRequest(int clientSockfd, string dir){


	// read/write data from/into the connection
	bool isEnd = false;
	char buf[1000] = { 0 };
	stringstream ssOverall;
	stringstream ssIteration;
	const string endingStr = "\r\n\r\n";
	unsigned int endingCount = 0;

	while (!isEnd) {
		memset(buf, '\0', sizeof(buf));

		if (recv(clientSockfd, buf, 1000, 0) == -1) {
			perror("recv");
			return;// 5;
		}

		ssOverall << buf;
		ssIteration << buf;
		string currString = ssIteration.str();

		for(unsigned int i = 0; i < currString.length(); i++){
			if(currString[i] == endingStr[endingCount])
				endingCount++;
			else
				endingCount = 0;
			if(endingCount == 4){
				string totalReqString = ssOverall.str();
				// cout << "--------totalReqString--------" << endl << totalReqString << endl;
				vector<uint8_t> decoded(totalReqString.begin(), totalReqString.end());
				HttpRequest req = HttpRequest::decode((ByteBlob)decoded);
				HttpResponse resp = processRequest(req, dir); //Process the request object

				ByteBlob respBB = resp.encode();
				uint8_t* respBytes = &respBB[0];
		  	int respBytesSize = sizeof(uint8_t) * respBB.size();

				// cout << "Num bytes being sent total: " << respBB.size() << endl;
				// cout << "Num bytes being sent, data: " << resp.getData().size() << endl;
				std::ofstream os("asdfasdfasdf.jpg");
				if (!os) {
					std::cerr<<"Error writing to ..."<<std::endl;
				}
				else {
					HttpResponse decodedResp = HttpResponse::decode(respBB);
					// ByteBlob data = resp.getData();
					ByteBlob data = decodedResp.getData();
					for(ByteBlob::iterator x=data.begin(); x<data.end(); x++){
						os << *x;
					}
					os.close();
				}
				if (send(clientSockfd, respBytes, respBytesSize, 0) == -1) {
					perror("send");
					return;// 6;
				}

				//ssOverall.str(""); doesn't 	matter, we're closing connection
				//endingCount = 0;
				isEnd = true;
				break;
			}
		}
	}
	close(clientSockfd);
	cout << "Server closing" << endl;;
}
开发者ID:jgbenito7,项目名称:CS118,代码行数:69,代码来源:web-server.cpp


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