public UnityRequest(UnityHttpClientV2 inst, string url, HttpRequest request, object previousUserData, int requestId) : base(inst, request) { self = inst; OriginalRequest = request; RequestId = requestId; PreviousUserData = previousUserData; Request = new UnityWebRequest(url); // Auto-choose HTTP method Request.method = request.Method ?? (request.Body != null ? "POST" : "GET"); // TODO Missing functionality (currently unsupported by UnityWebRequest). // req.SetRequestHeader("User-agent", request.UserAgent); // req.keepAlive = true; foreach (var pair in request.Headers) { Request.SetRequestHeader(pair.Key, pair.Value); } if (OriginalRequest.Body != null) { UploadHandler uploader = new UploadHandlerRaw(OriginalRequest.Body); if (ContentType != null) uploader.contentType = ContentType; Request.uploadHandler = uploader; } Request.downloadHandler = new DownloadHandlerBuffer(); }
public static UnityWebRequest Post(string uri, Dictionary<string, string> formFields) { UnityWebRequest request = new UnityWebRequest(uri, "POST"); UploadHandler handler = new UploadHandlerRaw(SerializeSimpleForm(formFields)) { contentType = "application/x-www-form-urlencoded" }; request.uploadHandler = handler; request.downloadHandler = new DownloadHandlerBuffer(); return request; }
public static UnityWebRequest Post(string uri, List<IMultipartFormSection> multipartFormSections, byte[] boundary) { UnityWebRequest request = new UnityWebRequest(uri, "POST"); UploadHandler handler = new UploadHandlerRaw(SerializeFormSections(multipartFormSections, boundary)) { contentType = "multipart/form-data; boundary=" + Encoding.UTF8.GetString(boundary, 0, boundary.Length) }; request.uploadHandler = handler; request.downloadHandler = new DownloadHandlerBuffer(); return request; }