- Home /
Question by
pavank1 · Jan 25, 2018 at 06:18 PM ·
unity 5networkingevent triggeringhttp
HTTP Post at an event trigger
I would like to call a http POST with some data during run time for an event. Unity manual gives the following method for http methods. However, the method is called during start and I can't trigger the post method during runtime from update as the method is a coroutine and also it is a blocking call -
public class MyBehavior : MonoBehaviour {
void Start() {
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://www.server.com/form", formData);
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
Debug.Log("Form upload complete!");
}
}
}
How can I call the http post from update as an event trigger -
public class MyBehavior : MonoBehaviour {
void Update() {
if (Input.GetMouseButtonDown (0)) {
//Upload(); // E.g.,
}
}
}
I am learning unity so apologies if this is not standard practice.
Comment
Your answer

Follow this Question
Related Questions
UNET RPG variable sync help 1 Answer
Question regarding unity mobile multiplayer game 0 Answers
Remote database for leaderboard 2 Answers
Death handling peculiarly 0 Answers