瀏覽代碼

POST上传表单时,有些内容不需要转成url编码;

scbc.sat2 5 年之前
父節點
當前提交
b6c5096857
共有 3 個文件被更改,包括 40 次插入266 次删除
  1. 2 2
      SATHTTP/SATHTTP/CurlClient.cpp
  2. 37 263
      SATHTTP/SATHTTP/SATHTTP.cpp
  3. 1 1
      SATHTTP/SATHTTP/SATHTTP.h

+ 2 - 2
SATHTTP/SATHTTP/CurlClient.cpp

@@ -5,7 +5,7 @@
 
 CCurlClient::CCurlClient(void)
 {
-	m_bDebug = FALSE;
+	m_bDebug = TRUE;
 	m_headers = NULL;
 }
 
@@ -789,7 +789,7 @@ CURLcode CCurlClient::PostFile(std::string url, std::string text, std::string fi
 	struct curl_httppost* formpost = NULL;
 	struct curl_httppost* lastptr = NULL;
 	rmcode = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "requestMsg", CURLFORM_COPYCONTENTS, text.c_str(), CURLFORM_END);
-	rmcode = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "uploads", CURLFORM_FILECONTENT, file.c_str(), CURLFORM_END);
+	rmcode = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "uploads", CURLFORM_FILE, file.c_str(), CURLFORM_END);
 
 	// ÉèÖÃ±íµ¥²ÎÊý
 	res = curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

+ 37 - 263
SATHTTP/SATHTTP/SATHTTP.cpp

@@ -35,6 +35,22 @@ using namespace std;
 
 bool MKDIR(LPCTSTR dir);
 
+__if_not_exists(NotifyJobStart)
+{
+	int NotifyJobStart(std::string url, const SATParameters::STNotifyJobStartReq &stNotifyJobStartReq, SATParameters::STNotifyJobStartResp &stNotifyJobStartResp) throw()
+	{
+		return SetResult(url, stNotifyJobStartReq, stNotifyJobStartResp);
+	}
+}
+
+__if_not_exists(ProcessJob)
+{
+	int ProcessJob(std::string url, const SATParameters::STJobProcessReq &stJobProcessReq, SATParameters::STJobProcessResp &stJobProcessResp) throw()
+	{
+		return SetResultList(url, stJobProcessReq, stJobProcessResp);
+	}
+}
+
 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 {
 	int nRetCode = 0;
@@ -48,267 +64,19 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	}
 	else
 	{
-		// TODO: 在此处为应用程序的行为编写代码。
-		//std::string host = "http://10.118.158.52:8580";//"http://10.118.158.198:8090";
 		std::string host = "http://10.118.158.198:8090";
-		SATParameters::STDevice stDevice;
-		stDevice.strStatus = "0";
-		stDevice.strDeviceSerial = "192.168.1.119:5555";
-		stDevice.strHardwareVersion = "MS6488";
-		stDevice.strManu = "MStar";
-		stDevice.strDeviceMac = "";
-		stDevice.strLastJobStartTime = "";
-		stDevice.strLastTimeBreak = "";
-		stDevice.strComments = "";
-		stDevice.strCPU = "";
-		stDevice.strSoftwareVersion = "1522659174";
-		stDevice.strPhoneNumber = "";
-		stDevice.strLastJobFinishTime = "";
-		stDevice.strMemory = "";
-		stDevice.strModel = "Generic Linux on tcl_ms6488_cn_64_n";
-		stDevice.strLastJob = "";
-		stDevice.strLastTimeConnected = "2019-12-16 10:16:01";
-		stDevice.strElectric = "";
-		// ##########################先登录##############################;
-		SATParameters::STLoginReq stLoginReq;
-		SATParameters::STLoginResp stLoginResp;
-		std::string url = host + "/btc_execute_se/ajaxInteractiveManage!executeLogin.action";
-		// 示例值;
-		stLoginReq.strUserName = "superAdmin";
-		stLoginReq.strStatus = "0";
-		stLoginReq.strDeleteStatus = "";
-		stLoginReq.strIP = "10.118.158.175";
-		stLoginReq.strStorage = "";
-		stLoginReq.strConnectTime = "";
-		stLoginReq.strExecuteName = "";
-		stLoginReq.strMAC = "40:16:7e:23:10:53";
-		stLoginReq.strDisconnectTime = "";
-		stLoginReq.strPassword = "123456";
-		stLoginReq.strCPU = "";
-
-		if ( !Login(url, stLoginReq, stLoginResp) )
-		{
-			system("pause");
-			return -1;
-		}
-
-		printf("登录返回:code=%s, msg=%s, str=%s, portCount=%d, companyid=%d, runnertoken=%s\n",
-			stLoginResp.strCode.c_str(),
-			stLoginResp.strMessage.c_str(),
-			stLoginResp.strStr.c_str(),
-			stLoginResp.nPortCount,
-			stLoginResp.nCompanyId,
-			stLoginResp.strRunnerToken.c_str()
-			);		
-
-		while(true)
-		{
-			// ##########################更新设备信息##############################;
-			SATParameters::STUpdateDeviceReq stUpdateDeviceReq;
-			SATParameters::STUpdateDeviceResp stUpdateDeviceResp;
-			__if_not_exists(url)
-			{			
-				std::string url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
-			}
-			__if_exists(url)
-			{
-				url = host + "/btc_execute_se/ajaxInteractiveManage!updateDeviceMessage.action";
-			}
-
-			stUpdateDeviceReq.strStatus = "0";
-			stUpdateDeviceReq.strUserName = "superAdmin";		
-			stUpdateDeviceReq.strIP = "10.118.158.175";
-			stUpdateDeviceReq.strStorage = "228092536KB";
-			stUpdateDeviceReq.strRunnerName = "SAT-Admin";
-			stUpdateDeviceReq.strMAC = "40:16:7e:23:10:53";
-			stUpdateDeviceReq.strReportType = "1";
-			stUpdateDeviceReq.strStartTime = "2019-12-16 19:15:30";
-			stUpdateDeviceReq.strMemory = "8938544KB";
-			stUpdateDeviceReq.strEndTime = "";
-			stUpdateDeviceReq.strCPU = "24.7%";
-			stUpdateDeviceReq.devicelist.push_back(stDevice);
-
-			if ( UpdateDeviceMessage(url, stUpdateDeviceReq, stUpdateDeviceResp) )
-			{
-				printf("更新设备信息成功:code=%s, msg=%s, str=%s\n",
-					stLoginResp.strCode.c_str(),
-					stLoginResp.strMessage.c_str(),
-					stLoginResp.strStr.c_str());
-			}
-			else
-			{
-				printf("更新设备信息失败!\n");
-			}
-
-			// ##########################心跳包机制##############################;
-			SATParameters::STHeartbeatReq stHeartbeatReq;
-			SATParameters::STHeartbeatResp stHeartbeatResp;
-			__if_not_exists(url)
-			{			
-				std::string url = host + "/btc_execute_se/ajaxInteractiveManage!executeHeartbeat.action";
-			}
-			__if_exists(url)
-			{
-				url = host + "/btc_execute_se/ajaxInteractiveManage!executeHeartbeat.action";
-			}
-
-			// 示例值;
-			//stDevice.strStatus = "0";
-			//stDevice.strDeviceSerial = "192.168.1.119:5555";
-
-			stHeartbeatReq.strUserName = "superAdmin";
-			stHeartbeatReq.strRunnerMac = "40:16:7e:23:10:53";
-			stHeartbeatReq.devicelist.push_back(stDevice);
-			if ( Heartbeat(url, stHeartbeatReq, stHeartbeatResp) )
-			{
-				printf("登录返回:code=%s, msg=%s, str=%s\n",
-					stHeartbeatResp.strCode.c_str(),
-					stHeartbeatResp.strMessage.c_str(),
-					stHeartbeatResp.strStr.c_str());
-
-				// 判断是否有任务获取成功;
-				if ( stHeartbeatResp.vtTask.size() )
-				{
-					// #########################################################################################
-					// 判断任务是否在SAT上存在;(感觉没什么意义!!!)
-					SATParameters::STTask stTask = stHeartbeatResp.vtTask[0];
-					SATParameters::STNotifyJobStartReq stNotifyJobStartReq;
-					SATParameters::STNotifyJobStartResp stNotifyJobStartResp;
-
-					TCHAR szValue[36] = {0};
-					_itoa_s(stTask.nDeviceId, szValue, 10);
-					stNotifyJobStartReq.strDeviceId = szValue;
-
-					_itoa_s(stTask.nExecuteId, szValue, 10);
-					stNotifyJobStartReq.strExecuteId = szValue;
-
-					_itoa_s(stTask.nInstanceId, szValue, 10);
-					stNotifyJobStartReq.strInstanceId = szValue;					
-
-					_itoa_s(stTask.nTaskId, szValue, 10);
-					stNotifyJobStartReq.strTaskId = szValue;
-
-					stNotifyJobStartReq.strSignalImageUrl = "D:\\SAT\\Runner\\btc_runner_se\\runner\\output\\ODF_NPI_RT2841\\20191216101613370\\192.168.1.119_5555";
-
-					__if_not_exists(url)
-					{			
-						std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
-					}
-					__if_exists(url)
-					{
-						url = host + "/btc_execute_se/ajaxInteractiveManage!setResult.action";
-					}
-
-					// 查询任务是否已在SAT上存在;
-					if ( NotifyJobStart(url, stNotifyJobStartReq, stNotifyJobStartResp) )
-					{
-						// 更新设备为忙碌状态;
-						//stDevice.strStatus =  "2"; // 忙碌状态,此时请求Heartbeat将不会查询任务;
-						stDevice.strStatus = "2";
-						printf("NotifyJobStart 成功\n");
-					}
-					else
-					{
-						printf("NotifyJobStart 失败\n");
-					}
-
-					// #########################################################################################
-					// 开始Job;
-					SATParameters::STJobProcessReq stJobProcessReq;
-					SATParameters::STJobProcessResp stJobProcessResp;
-					__if_not_exists(url)
-					{			
-						std::string url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
-					}
-					__if_exists(url)
-					{
-						url = host + "/btc_execute_se/ajaxInteractiveManage!setResultList.action";
-					}
-
-					{
-						stJobProcessReq.strResultState = "1";
-						stJobProcessReq.strCaseScene = "";
-						stJobProcessReq.strCaseStep = "0";
-						stJobProcessReq.strApkMD5 = "";
-						stJobProcessReq.strCrashTime = "";
-						// 就是Task中的ExecuteId
-						_itoa_s(stTask.nExecuteId, szValue, 10);
-						stJobProcessReq.strRunnerId = szValue;
-						stJobProcessReq.strCPUInfo = "0";
-						stJobProcessReq.strRunnedActionNameList = "";
-						stJobProcessReq.strArtificialResult = "";
-						stJobProcessReq.strArtificialModify = "";
-						stJobProcessReq.strRunnerName = "";
-						stJobProcessReq.strTaskType = "FUNCTIONALITY";
-						stJobProcessReq.strCaseRepeat = "";
-						stJobProcessReq.strApplicationGroup = "";
-						// 实例Id;
-						_itoa_s(stTask.nInstanceId, szValue, 10);
-						stJobProcessReq.strInstanceId = szValue;
-						stJobProcessReq.strCaseId = "";
-						stJobProcessReq.strProgress = "0";
-						stJobProcessReq.strReusltMessage = "任务开始";
-						stJobProcessReq.strJobRepeat = "";
-						stJobProcessReq.strScreenShot = "";
-						stJobProcessReq.strStartTime = "2019-12-16 10:16:43";
-						stJobProcessReq.strCrashNumber = "";
-						stJobProcessReq.strCaseName = "";
-						stJobProcessReq.strFailedReason = "";
-						stJobProcessReq.strImgName = "";
-						stJobProcessReq.strCaseIndex = "";
-						// 实例Id;
-						_itoa_s(stTask.nDeviceId, szValue, 10);
-						stJobProcessReq.strDeviceId = szValue;
-						stJobProcessReq.strSceneIndex = "";
-						// 实例Id;
-						_itoa_s(stTask.nTaskId, szValue, 10);
-						stJobProcessReq.strTaskId = szValue;
-						stJobProcessReq.strAnalysis = "";
-						// 设备名称:即DeviceSerial;
-						stJobProcessReq.strDevnceName = stDevice.strDeviceSerial;
-						// 固定为:TOTAL
-						stJobProcessReq.strInfoType = "TOTAL";
-						// 如果是Android设备,需要通过adb获取;
-						stJobProcessReq.strMemoryInfo = stDevice.strMemory;
-						stJobProcessReq.strEndTime = "2019-12-16 10:18:20";
-						stJobProcessReq.strRoundNumber = "1";
-						stJobProcessReq.strResultType = "0";
-						stJobProcessReq.strOperationStep = "";
-					}
-
-					// 
-					if ( ProcessJob(url, stJobProcessReq, stJobProcessResp) )
-					{
-						// 开始下载脚本;
-						__if_not_exists(url)
-						{			
-							std::string url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
-						}
-						__if_exists(url)
-						{
-							url = host + "/btc_caseManagement_se/ajaxInteractiveManage!getCaseFileListUrl.action";
-						}
-						
-						SATParameters::STScriptUrlResp stScriptUrlResp;
-						std::vector<SATParameters::STCase>::iterator it = stTask.Job.vtCases.begin();
-						for ( ; it != stTask.Job.vtCases.end(); it++ )
-						{
-							if ( DownloadScript(url, it->strId, "D:\\SAT\\", stScriptUrlResp) )
-							{
-								printf("获取脚本下载地址成功:%s\n路径:%s\n", stScriptUrlResp.strURL.c_str(), stScriptUrlResp.strScripFile.c_str());
-							}
-							else
-							{
-								printf("获取脚本下载地址失败\n");
-							}
-						}						
-					}
-				}
-			}
-
-			Sleep(3000);
-		}
-		
+		SATParameters::STSaveLogReq stSaveLogReq;
+		SATParameters::STSaveLogResp stSaveLogResp;
+		std::string url = host + "/btc_execute_se/ajaxInteractiveManage!saveCaseOrTaskLog.action";
+
+		// 20191219092809213
+		stSaveLogReq.strUserId = "7";
+		stSaveLogReq.strExecuteId = "19";
+		stSaveLogReq.strCaseId = "1569";
+		stSaveLogReq.strFileType = "caseLogFile";
+		stSaveLogReq.strTaskId = "4220";
+		stSaveLogReq.strUploads = "D:\\SAT\\log.txt";
+		SaveCaseOrTaskLog(url, stSaveLogReq, stSaveLogResp);
 	}
 
 	system("pause");
@@ -1284,7 +1052,9 @@ SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATParameters::STSaveLo
 	}
 
 	char *pText = cJSON_Print(pRoot);
-	std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	// POST表单提交,此处不需要转url格式,注意避坑!
+	std::string post_data = pText;
 
 	// 释放堆内存;
 	if (pText)
@@ -1380,7 +1150,9 @@ SATHTTP_API int SaveResultFile(std::string url, const SATParameters::STSaveFileR
 	}
 
 	char *pText = cJSON_Print(pRoot);
-	std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	// POST表单提交,此处不需要转url格式,注意避坑!
+	std::string post_data = pText;
 
 	// 释放堆内存;
 	if (pText)
@@ -1462,7 +1234,9 @@ SATHTTP_API int SaveResultImg(std::string url, const SATParameters::STSaveImgReq
 	}
 
 	char *pText = cJSON_Print(pRoot);
-	std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	//std::string post_data = CharEncoding::EnCode_UTF8URL(pText);
+	// POST表单提交,此处不需要转url格式,注意避坑!
+	std::string post_data = pText;
 
 	// 释放堆内存;
 	if (pText)

+ 1 - 1
SATHTTP/SATHTTP/SATHTTP.h

@@ -363,7 +363,7 @@ SATHTTP_API int GetCaseFileListUrl(std::string url, std::string strCaseId, SATPa
 SATHTTP_API int DownloadScript(std::string url, std::string strCaseId, std::string strSaveDir, SATParameters::STScriptUrlResp &stScriptUrlResp) throw();
 
 // 停止Runner上的任务;
-// 注意:strInstnaceId暂时未确定是STTask.Id还是STTask.nInstanceId;
+// 注意:strInstnaceId对应的是STTask.nInstanceId;
 SATHTTP_API int StopTaskFromRunner(std::string url, std::string strInstnaceId, SATParameters::STStopTaskResp &stStopTaskResp) throw();
 
 SATHTTP_API int SaveCaseOrTaskLog(std::string url, const SATParameters::STSaveLogReq &stSaveLogReq, SATParameters::STSaveLogResp &stSaveLogResp) throw();