Example #1
0
    public static IEnumerator HttpGet(string url, HttpCallback callback = null)
    {
        UnityWebRequest request = UnityWebRequest.Get(url);

        yield return(request.SendWebRequest());

        JsonData jd = null;

        if (request.isNetworkError)
        {
            Debug.Log("request url: " + url + " error: " + request.error);
        }
        else if (request.responseCode == 200)
        {
            string text = request.downloadHandler.text;
            // Debug.Log(text);
            jd = JsonMapper.ToObject(text);
        }
        if (callback != null)
        {
            callback.Invoke(jd);
        }
    }
Example #2
0
 /// <summary>
 /// Raises <see cref="HttpCallback"/> event
 /// </summary>
 /// <param name="sender">Event sender - a <see cref="TcpClient"/> object representing agent client</param>
 /// <param name="e">Event parameters</param>
 protected virtual void OnHttpCallback(object sender, HttpCallbackEventArgs e)
 {
     HttpCallback?.Invoke(sender, e);
 }