RuralPowerCompetition_yizhe.../RuralPowerCompetition_yizheng1/Assets/Temp/yuanjinzhi/熔断器/TempSendVideo.cs

80 lines
2.7 KiB
C#

using Newtonsoft.Json.Linq;
using RuralPower;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class TempSendVideo : MonoBehaviour
{
void Start()
{
string path = Application.streamingAssetsPath + "/ScreenCaptures/2022_8_18/017/04_user-2022-08-18-52150s-800x600.mp4";
if (!File.Exists(path))
{
return;
}
string url = "http://192.168.1.213:8088/Handler/Pow/UploadFile.ashx";
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
keyValuePairs.Add("ExamId", "c7080a513ec043f2baf695e866efcb67");
keyValuePairs.Add("UserId", "USER202204211516089625");
keyValuePairs.Add("FileDesc", "停送电以及排除故障");
byte[] b = File.ReadAllBytes(path);
Debug.Log("文件获取成功");
StartCoroutine(Request.Post_Video(url,
keyValuePairs, b, ((a, s) =>
{
if ((bool)a)
{
Debug.Log(s);
}
})));
//RuralPowerAPI api = new RuralPowerAPI();
//string result = api.UploadFile("http://192.168.1.213:8088", "c7080a513ec043f2baf695e866efcb67", "USER202204211516089625",
// "停送电以及排除故障",path
// );
//Debug.Log(result);
////http://192.168.1.213:8088
////http://umayle.com:8092
}
}
/*
* string ExamId, string UserId, string FileDesc, string FilePath
* public static IEnumerator Post_Video(string url, Dictionary<string, string> keyValuePairs, string fileName, byte[] b, System.Action<bool, string> action)
{
WWWForm form = new WWWForm();
foreach (var item in keyValuePairs)
{
form.AddField(item.Key, item.Value);
}
form.AddBinaryData(fileName+".mp4", b,"test.mp4");
UnityWebRequest webRequest = UnityWebRequest.Post(url, form);
yield return webRequest.SendWebRequest();
if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
{
Debug.Log(webRequest.error);
action.Invoke(false, string.Empty);
}
else
{
string msg = webRequest.downloadHandler.text;
Debug.Log(msg);
JObject JO = JObject.Parse(msg);
if (JO["state"].ToString().Equals("true") || JO["state"].ToString().Equals("True"))
{
action.Invoke(true, JO["data"].ToString());
}
else
{
action.Invoke(false, string.Empty);
}
}
}
*
* */