-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendData2Server_v2.cs
More file actions
59 lines (49 loc) · 1.63 KB
/
SendData2Server_v2.cs
File metadata and controls
59 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class SendData2Server_v2 : MonoBehaviour
{
public Button PostBucketButton = null;
void Start()
{
PostBucketButton.onClick.AddListener(() => { PostObject(); });
}
void PostObject()
{
StartCoroutine(Upload());
}
IEnumerator Upload()
{
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
formData.Add(new MultipartFormDataSection("field1=foo&field2=bar"));
formData.Add(new MultipartFormFileSection("my file data", "myfile.txt"));
UnityWebRequest www = UnityWebRequest.Post("http://localhost:80/", formData);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
}
//IEnumerator Upload()
//{
// //byte[] myData = System.Text.Encoding.UTF8.GetBytes("This is some test data");
// string myData = "This is some test data";
// //UnityWebRequest www = UnityWebRequest.Put("http://www.my-server.com/upload", myData);
// UnityWebRequest www = UnityWebRequest.Put("http://localhost:80/", myData);
// yield return www.SendWebRequest();
// if (www.isNetworkError || www.isHttpError)
// {
// Debug.Log(www.error);
// }
// else
// {
// Debug.Log("Upload complete!");
// }
//}
}