private async void SendToServer(GPerfSession session, string logPath) { var result = await RemoteUtil.PostSessionAsync(m_URL, session.ToByteArray(), "application/x-protobuf"); /*{"message":"OK", * "uploadLogs":{ * "url":"http://hb.ix2.cn:8008/rog2/s3logs/client/1970/1/19/580fe550929721ef0c93f1e089f5c8fa.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20201027T103655Z&X-Amz-SignedHeaders=content-type%3Bhost%3Bx-amz-acl&X-Amz-Expires=600&X-Amz-Credential=test-key%2F20201027%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=a82e7cb10e469ea54da0fea1013878d9129777e3e60f55b28b9ca7951d331afa", * "method":"PUT", * "headers":{"x-amz-acl":"public-read","host":"hb.ix2.cn:8008","content-type":"application/gzip"}, * "compression":"GZIP", * "expires":1603795615}} */ if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(logPath) && File.Exists(logPath)) { Debug.Log($"{GPerfUtil.LOG_NAME}::SendToServer->Send Log to Server.result = {result}"); SendLogToServer(result, logPath); } }
private async void SendLogToServer(string result, string logPath) { try { JObject resultJsonObj = JObject.Parse(result); JToken messageToken = resultJsonObj["message"]; if (messageToken != null && messageToken.Value <string>() == "OK") { var uploadLogInfo = resultJsonObj["uploadLogs"]; if (uploadLogInfo != null) { var logBytes = await RemoteUtil.GZipFileAsync(logPath); if (logBytes != null && logBytes.Length > 0) { var headerInfo = uploadLogInfo["headers"]; var url = uploadLogInfo["url"].Value <string>(); var method = uploadLogInfo["method"].Value <string>(); var compression = uploadLogInfo["compression"].Value <string>(); Dictionary <string, string> headerDic = new Dictionary <string, string>(); var header = headerInfo.Next; while (header != null) { headerDic.Add(header.Path, header.Value <string>()); } //Debug.Log($"{GPerfUtil.LOG_NAME}::RemoteRecorder->upload log file"); //目前服务器没有给返回值,只要通过地址能拿到压缩的日志文件即可认为成功 //var response = await RemoteUtil.PutLogAsync(url, logBytes, 5, headerDic); //Debug.Log($"{GPerfUtil.LOG_NAME}::RemoteRecorder->upload Finished.result = {response}"); } } } } catch (Exception e) { Debug.LogError("RemoteRecorder::SendLogToServer->" + e.Message); } }