Пример #1
0
void SimpleCrawler::scanHtml(char* html)
{
	NodeInfo info;

	char* nodeBegin = strstr(html,"<");

	while(nodeBegin!=nullptr)
	{
		char *aNext,*imgNext;
		if(aNext = ParseANode(nodeBegin,&info))
		{
			if(!isInVisibleVec(info))
			{
				m_visibleList.push_back(info);
				m_workList.push_back(info);
				m_outputA<<UTF8ToGBK(info.text)<<":\nhost:  "<<info.host<<"\nres:  "<<info.resource<<"\n"<<endl;
			}
		}

		if(imgNext = ParseImgNode(nodeBegin,&info))
		{
			if(!isInVisibleVec(info))
			{
				m_outputImg<<UTF8ToGBK(info.text)<<":\nhost:  "<<info.host<<"\nres:  "<<info.resource<<"\n"<<endl;
			}
		}

		nodeBegin = strstr(nodeBegin+1,"<");
	}
}
Пример #2
0
bool WorkBook::loadSharedStrings(char* data, unsigned size)
{
	pugi::xml_document doc;
	pugi::xml_parse_result pResult = doc.load_buffer(data, size, pugi::parse_default, pugi::encoding_auto);//doc.load_file("G:\\zData\\openxml_xlsx\\员工通讯录abc\\xl\\sharedStrings.xml", pugi::parse_default, pugi::encoding_auto);
	if (pResult == false)
	{
		return false;
	}

	pugi::xml_node root = doc.first_child();
	assert(root.name() == std::string("sst"));
	
	for (pugi::xml_node si = root.first_child(); si; si = si.next_sibling())
	{
		if (si.name() == std::string("si"))
		{
			const char* svalue = si.child_value("t");
			

			std::string strValue = svalue;
			std::string strRetValue = svalue;
			UTF8ToGBK(strRetValue , strValue);

			std::cout << strRetValue.c_str() << std::endl;

			//utf8 -> ascII. or not.
			m_sharedStrings.m_sharedStrings.push_back(strRetValue);
		}
	}
	return true;
}
Пример #3
0
int CChangePWD::WebChangePassWord()
{
	//char *msg = (char *)malloc(MAX_BUFFER_SIZE);
	
	char msg[MAX_BUFFER_SIZE] = { 0 };
	char http[MAX_BUFFER_SIZE] = { 0 };
	char http2[MAX_BUFFER_SIZE] = { 0 };
	char data[MAX_BUFFER_SIZE] = { 0 };
	char ip[16] = {0};
	CGKloginDlg zte;
#ifdef WIN32
#define snprintf _snprintf
#endif
	zte.GetMacIP(Config.m_csNetCard, ip, NULL);
	if (strlen(edubas) == 0)
		snprintf(data, MAX_BUFFER_SIZE, "&userName1=%s&password1=%s&password2=%s&password3=%s&eduuser=%s&edubas=113.98.13.29", Account, PassWordOld, PassWordNew1, PassWordNew2, ip);
	else
		snprintf(data, MAX_BUFFER_SIZE, "&userName1=%s&password1=%s&password2=%s&password3=%s&eduuser=%s&edubas=%s", Account, PassWordOld, PassWordNew1, PassWordNew2, ip, edubas);
	SendPost(http2, MAX_BUFFER_SIZE, "http://125.88.59.131:10001/changePassword.do", NULL, DOWNTIMEOUT, NULL, NULL, NULL, data);
	UTF8ToGBK((unsigned char*)http2, (unsigned char*)http, MAX_BUFFER_SIZE);
	GetHTTPMsg(http, MAX_BUFFER_SIZE, 1, "<div id=\"success\">", NULL, NULL, msg, NULL, NULL, NULL, "<div>");
	if (strlen(msg)){
		char Remind[MAX_BUFFER_SIZE] = { 0 };
		sprintf(Remind, "网页认证密码%s", msg);
		AfxMessageBox(Remind, MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
		if (strstr(Remind, "成功") != 0)
			return 1;
	}
	else
	{ 
		AfxMessageBox("网页认证密码修改失败", MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
	}
	//free(msg);
	return 0;
}
Пример #4
0
int main()
{
	etcd::Client<etcd::RapidReply> client("172.16.1.10", 2379);
	std::string a = GBKToUTF8("你好");
	
	etcd::RapidReply reply = client.Set("/message", a.c_str());
	etcd::RapidReply reply2 = client.Get("/message1");
	etcd::RapidReply::KvPairs result;
	reply2.GetAll(result);
	std::string b = UTF8ToGBK(result["/message1"].c_str());

	return 0;
}
Пример #5
0
// 测试函数入口:
int main(int argc, char * argv[]) {

	//
	complexStrcutTest();

	// 初始化restful请求类的实例
	RESTFulRequestor<Person> request;

	/**********************************************************************************/
	// 中文乱码测试:
	string GetChineseURL = "http://172.16.10.14:1569/datasong/dataService/test/student/0EfwrIIfQUc9FuPbQNTeYx20161014113922976";
	string GetChineseResult = request.getGETResponse2Stream(GetChineseURL);
	cout << UTF8ToGBK(GetChineseResult) << endl;
	//string fileName = "C:\\Users\\wentao\\Desktop\\out.txt";
	//bool isGetSuccess = request.getGETResponseAsFile(GetChineseURL, fileName);
	
	// PUT方法调用测试:
	string PutURL = "http://172.16.10.14:1569/datasong/dataService/iscas/mission";
	string PutParamters = "{\"_actionid\" : \"1\", \"_id\" : \"\",  \"_name\" : \"任务1\",  \"_remark\" : \"我的第一个任务\",  \"_time\" : 2.119999999999999}";
	cout << PutParamters << endl;
	string PutResult = request.getPUTRequest2Stream(PutURL, GBKToUTF8(PutParamters));
	cout << UTF8ToGBK(PutResult) << endl;
	//string PutFileName = "C:\\Users\\wentao\\Desktop\\out.txt";
	//bool isPUTSuccess = request.getPUTRequestAsFile(GetChineseURL, PutParamters, PutFileName);

	// POST方法调用测试:
	string POSTURL = "http://172.16.10.14:1569/datasong/dataService/test/mission";
	string POSTParamters = "{\"search\":{\"field\":\"_actionid\",\"NAME\":\"term\",\"values\":[\"1\"]},\"start\":0,\"size\":10} ";
	string POSTResult = request.getPOSTRequest2Stream(PutURL, PutParamters);
	cout << UTF8ToGBK(POSTResult) << endl;


	/**********************************************************************************/
	// 测试:从自定义结构体转换为JSON
	string serializitionResult = request.serialize(p);
	cout << "转换后的JSON结果为:" << serializitionResult << endl;
	// 测试:从JSON转换到自定义结构体
	Person deserializitionResult;
	bool result = request.deserialize(deserializitionResult, serializitionResult);
	if (result) {
		cout << "反序列化成功!" << endl;
		cout << deserializitionResult.age << endl;
		cout << deserializitionResult.name << endl;
		cout << deserializitionResult.city << endl;
	}

	/**********************************************************************************/
	// 综合测试入口:
	if (argc<3) {	// 检查参数个数:
		cout << "at least input 2 paramters" << endl;
	}
	// 获取参数:
	int testOption = atoi(argv[1]);
	cout << "current option is: "<< testOption << endl;

	// 根据输入参数执行测试:
	switch (testOption)
	{
	// 测试0:访问网址,并且将网页返回内容显示在屏幕上
	case 0: {
		if (argc != 3) {
			cout << "call method: exe 0 URLAddress" << endl;
			break;
		}
		string testURL = argv[2];
		cout << "按照GET请求访问网址:" << testURL << endl;
		cout << "返回结果为:" << endl;
		request.getGETResponse2Screen(testURL);
		break;
	}
	// 测试1:使用GET方法访问URL,并将结果作为字符串返回
	case 1: {
		if (argc != 3) {
			cout << "call method: exe 1 URLAddress" << endl;
			break;
		}
		string testURL = argv[2];
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		string result = request.getGETResponse2Stream(testURL);
		cout << "返回结果为:" << UTF8ToGBK(result) << endl;
		break;
	}
	// 测试2:使用GET方法访问URL,并将结果写入指定的文件中
	case 2: {
		if (argc != 4) {
			cout << "call method: exe 2 URLAddress LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string restorFilePath = argv[3];
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getGETResponseAsFile(testURL, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" <<endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试3:使用POST方法访问URL,并将结果作为字符串返回
	case 3: {
		if (argc != 4) {
			cout << "call method: exe 3 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用POST方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getPOSTRequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试4:使用POST方法访问URL,并将结果写入到指定的文件中
	case 4: {
		if (argc != 5) {
			cout << "call method: exe 4 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用GET方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getPOSTRequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试5:使用DELETE方法访问URL,并将结果作为字符串返回
	case 5: {
		if (argc != 4) {
			cout << "call method: exe 5 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getDELETERequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试6:使用DELETE方法访问URL,并将结果写入到指定的文件中
	case 6: {
		if (argc != 5) {
			cout << "call method: exe 6 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getDELETERequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试7:使用PUT方法访问URL,并将结果作为字符串返回
	case 7: {
		if (argc != 4) {
			cout << "call method: exe 7 URLAddress requestParameter" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		// 执行操作:
		cout << "使用DELETE方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数为:" << requestParameter << endl;
		string buffer = request.getPUTRequest2Stream(testURL, requestParameter);
		if (buffer.empty()) {
			cout << "获取网络请求失败" << endl;
		}
		else {
			cout << "返回结果为:" << endl;
			cout << UTF8ToGBK(buffer) << endl;
		}
		break;
	}
	// 测试8:使用DELETE方法访问URL,并将结果写入到指定的文件中
	case 8: {
		if (argc != 5) {
			cout << "call method: exe 8 URLAddress requestParameter LocalFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string restorFilePath = argv[4];
		// 执行操作:
		cout << "使用PUT方法请求RESTFul接口:" << testURL << endl;
		cout << "指定的参数:" << requestParameter << endl;
		cout << "将返回结果写入指定的文件:" << restorFilePath << endl;
		bool result = request.getPUTRequestAsFile(testURL, requestParameter, restorFilePath);
		if (result) {
			cout << "返回结果写入文件成功" << endl;
		}
		else {
			cout << "返回结果写入文件失败" << endl;
		}
		break;
	}
	// 测试9:form表单提交本地文件到指定的URL
	case 9: {
		if (argc != 5) {
			cout << "call method: exe 9 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单提交本地文件:" << localFilePath << endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadSimpleFormFile(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试10:form表单以multipart方式提交本地文件到指定的URL
	case 10: {
		if (argc != 5) {
			cout << "call method: exe 10 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单以multipart格式提交本地文件:" << localFilePath << endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadMultipartFormFile(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试11:form表单以multipart方式将本地文件转换为文件流,然后提交到指定的URL
	case 11: {
		if (argc != 5) {
			cout << "call method: exe 11 URLAddress uploadFileName localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string uploadFileName = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "form表单以multipart方式将本地文件:" << localFilePath <<" 转换为文件流"<< endl;
		cout << "以文件名为:" << uploadFileName << endl;
		cout << "提交到指定的URL:" << testURL << endl;
		bool result = request.uploadMultipartFormFileStream(testURL, uploadFileName, localFilePath);
		if (result) {
			cout << "执行成功,请在服务器端查看上传文件" << endl;
		}
		break;
	}
	// 测试12:从指定的URL下载文件到本地路径:
	case 12: {
		if (argc != 5) {
			cout << "call method: exe 12 URLAddress requestParameter localFilePath" << endl;
			break;
		}
		string testURL = argv[2];
		string requestParameter = argv[3];
		string localFilePath = argv[4];
		// 执行操作:
		cout << "从指定的URL:" << testURL << endl;
		cout << "按照参数:" << requestParameter << endl;
		cout << "下载文件到本地路径:" << localFilePath << endl;
		int result = request.SyncDownload(testURL, requestParameter, localFilePath);
		if (result == 0) {
			cout << "执行成功,请在本地路径查看下载文件" << endl;
		}
		break;
	}
	default:
		break;
	}


	// Finish test
	return 0;
}