-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicHttpClient.cs
42 lines (37 loc) · 1.27 KB
/
BasicHttpClient.cs
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
// ===============================
// AUTHOR : Marc Müller goedle.io GmbH
// CREATE DATE : 31.07.2018
// PURPOSE : Basic HTTP Client to send a post request
//=================================
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
namespace goedle.detail
{
public class BasicHttpClient : MonoBehaviour
{
public void sendPost(string content, IGoedleWebRequest gwr, IGoedleUploadHandler guh)
{
StartCoroutine(basicPostClient(content, gwr, guh));
}
public IEnumerator basicPostClient(string content, IGoedleWebRequest gwr, IGoedleUploadHandler guh)
{
guh.add(content);
gwr.unityWebRequest = new UnityWebRequest();
using (gwr.unityWebRequest)
{
gwr.method = "POST";
gwr.url = "url";
gwr.uploadHandler = guh.uploadHandler;
gwr.unityWebRequest.SetRequestHeader("Content-Type", "application/json");
gwr.chunkedTransfer = false;
yield return gwr.unityWebRequest.SendWebRequest();
if (gwr.isNetworkError || gwr.isHttpError)
{
Debug.LogError("isHttpError: " + gwr.isHttpError);
Debug.LogError("isNetworkError: " + gwr.isNetworkError);
}
}
}
}
}