我正在尝试使用 UnityWebRequest.Post() 上传多个文件,这是我的代码。
public void UploadFiles()
{
string[] path = new string[3];
path[0] = "D:/File1.txt";
path[1] = "D:/File2.txt";
path[2] = "D:/File3.txt";
UnityWebRequest[] files = new UnityWebRequest[3];
WWWForm form = new WWWForm();
for (int i = 0; i < files.Length; i++)
{
files[i] = UnityWebRequest.Get(path[i]);
form.AddBinaryData("files[]", files[i].downloadHandler.data, Path.GetFileName(path[i]));
}
UnityWebRequest req = UnityWebRequest.Post("http://localhost/File%20Upload/Uploader.php", form);
yield return req.SendWebRequest();
if (req.isHttpError || req.isNetworkError)
Debug.Log(req.error);
else
Debug.Log("Uploaded " + files.Leng