private getHeaders ( ) : string>.Dictionary |
||
Résultat | string>.Dictionary |
internal static IEnumerator SendRequest(HttpRequest request, Action <int /*statusCode*/, string /*data*/, string /*error*/> completionHandler) { WWW www; if (request.HTTPMethod == HttpRequest.HTTPMethodType.POST) { Dictionary <string, string> headers = new Dictionary <string, string>(); WWWForm form = new WWWForm(); foreach (var entry in Utils.HashtableToDictionary <string, string>(form.headers)) { headers[entry.Key] = entry.Value; } foreach (var entry in request.getHeaders()) { headers[entry.Key] = entry.Value; } byte[] bytes = Encoding.UTF8.GetBytes(request.HTTPBody); www = new WWW(request.URL, bytes, headers); } else { www = new WWW(request.URL); } yield return(www); int statusCode = ReadStatusCode(www); string data = www.text; string error = www.error; if (completionHandler != null) { completionHandler(statusCode, data, error); } }
internal static IEnumerator SendRequest(HttpRequest request, Action <int /*statusCode*/, string /*data*/, string /*error*/> completionHandler) { // timeout feature added in 5.6.2f1 #if UNITY_5_6_OR_NEWER && !UNITY_5_6_0 && !UNITY_5_6_1 UnityWebRequest www = new UnityWebRequest(); www.url = request.URL; www.timeout = request.TimeoutSeconds; www.downloadHandler = new DownloadHandlerBuffer(); if (request.HTTPMethod == HttpRequest.HTTPMethodType.POST) { www.method = UnityWebRequest.kHttpVerbPOST; foreach (var entry in request.getHeaders()) { www.SetRequestHeader(entry.Key, entry.Value); } byte[] bytes = Encoding.UTF8.GetBytes(request.HTTPBody); www.uploadHandler = new UploadHandlerRaw(bytes); www.chunkedTransfer = false; } else { www.method = UnityWebRequest.kHttpVerbGET; } #if UNITY_2017_2_OR_NEWER yield return(www.SendWebRequest()); #else yield return(www.Send()); #endif if (completionHandler != null) { completionHandler((int)www.responseCode, www.downloadHandler.text, www.error); } #else WWW www; if (request.HTTPMethod == HttpRequest.HTTPMethodType.POST) { Dictionary <string, string> headers = new Dictionary <string, string>(); WWWForm form = new WWWForm(); foreach (var entry in Utils.HashtableToDictionary <string, string>(form.headers)) { headers[entry.Key] = entry.Value; } foreach (var entry in request.getHeaders()) { headers[entry.Key] = entry.Value; } byte[] bytes = Encoding.UTF8.GetBytes(request.HTTPBody); www = new WWW(request.URL, bytes, headers); } else { www = new WWW(request.URL); } float timer = 0; bool timedout = false; while (!www.isDone) { if (timer > request.TimeoutSeconds) { timedout = true; break; } timer += Time.deltaTime; yield return(null); } int statusCode = 1001; string data = null; string error = null; if (timedout) { www.Dispose(); error = "connect() timed out"; } else { statusCode = ReadStatusCode(www); data = www.text; error = www.error; } if (completionHandler != null) { completionHandler(statusCode, data, error); } #endif // UNITY_5_6_OR_NEWER }
internal static IEnumerator SendRequest(HttpRequest request, Action <int /*statusCode*/, string /*data*/, string /*error*/> completionHandler) { WWW www; if (request.HTTPMethod == HttpRequest.HTTPMethodType.POST) { Dictionary <string, string> headers = new Dictionary <string, string>(); WWWForm form = new WWWForm(); foreach (var entry in Utils.HashtableToDictionary <string, string>(form.headers)) { headers[entry.Key] = entry.Value; } foreach (var entry in request.getHeaders()) { headers[entry.Key] = entry.Value; } byte[] bytes = Encoding.UTF8.GetBytes(request.HTTPBody); www = new WWW(request.URL, bytes, headers); } else { www = new WWW(request.URL); } float timer = 0; bool timedout = false; while (!www.isDone) { if (timer > request.TimeoutSeconds) { timedout = true; break; } timer += Time.deltaTime; yield return(null); } int statusCode = 1001; string data = null; string error = null; if (timedout) { www.Dispose(); error = "connect() timed out"; } else { statusCode = ReadStatusCode(www); data = www.text; error = www.error; } if (completionHandler != null) { completionHandler(statusCode, data, error); } }
internal static IEnumerator SendRequest(HttpRequest request, Action<int /*statusCode*/, string /*data*/, string /*error*/> completionHandler) { WWW www; if (request.HTTPMethod == HttpRequest.HTTPMethodType.POST) { Dictionary<string, string> headers = new Dictionary<string, string>(); WWWForm form = new WWWForm(); foreach (var entry in Utils.HashtableToDictionary<string, string>(form.headers)) { headers[entry.Key] = entry.Value; } foreach (var entry in request.getHeaders()) { headers[entry.Key] = entry.Value; } byte[] bytes = Encoding.UTF8.GetBytes(request.HTTPBody); www = new WWW(request.URL, bytes, headers); } else { www = new WWW(request.URL); } float timer = 0; bool timedout = false; while (!www.isDone) { if (timer > request.TimeoutSeconds) { timedout = true; break; } timer += Time.deltaTime; yield return null; } int statusCode = 1001; string data = null; string error = null; if (timedout) { www.Dispose(); error = "connect() timed out"; } else { statusCode = ReadStatusCode(www); data = www.text; error = www.error; } if (completionHandler != null) { completionHandler(statusCode, data, error); } }