예제 #1
0
 private static void SetupPost(UnityWebRequest request, string postData)
 {
     byte[] data = null;
     if (!string.IsNullOrEmpty(postData))
     {
         string s = WWWTranscoder.DataEncode(postData, Encoding.UTF8);
         data = Encoding.UTF8.GetBytes(s);
     }
     request.uploadHandler             = new UploadHandlerRaw(data);
     request.uploadHandler.contentType = "application/x-www-form-urlencoded";
     request.downloadHandler           = new DownloadHandlerBuffer();
 }
        public static byte[] SerializeSimpleForm(Dictionary <string, string> formFields)
        {
            string queryString = "";

            foreach (KeyValuePair <string, string> pair in formFields)
            {
                if (queryString.Length > 0)
                {
                    queryString += "&";
                }
                queryString += WWWTranscoder.DataEncode(pair.Key) + "=" + WWWTranscoder.DataEncode(pair.Value);
            }
            return(System.Text.Encoding.UTF8.GetBytes(queryString));
        }
        private static void SetupPostWwwForm(UnityWebRequest request, string postData)
        {
            request.downloadHandler = new DownloadHandlerBuffer();
            if (string.IsNullOrEmpty(postData))
            {
                return;  // no data to send, nothing more to setup
            }
            byte[] payload    = null;
            string urlencoded = WWWTranscoder.DataEncode(postData, System.Text.Encoding.UTF8);

            payload = System.Text.Encoding.UTF8.GetBytes(urlencoded);
            request.uploadHandler             = new UploadHandlerRaw(payload);
            request.uploadHandler.contentType = "application/x-www-form-urlencoded";
        }
        public static byte[] SerializeSimpleForm(Dictionary <string, string> formFields)
        {
            string text = "";

            foreach (KeyValuePair <string, string> keyValuePair in formFields)
            {
                if (text.Length > 0)
                {
                    text += "&";
                }
                text = text + WWWTranscoder.DataEncode(keyValuePair.Key) + "=" + WWWTranscoder.DataEncode(keyValuePair.Value);
            }
            return(Encoding.UTF8.GetBytes(text));
        }
        public static UnityWebRequest Post(string uri, string postData)
        {
            UnityWebRequest unityWebRequest = new UnityWebRequest(uri, "POST");

            byte[] data = null;
            if (!string.IsNullOrEmpty(postData))
            {
                string s = WWWTranscoder.DataEncode(postData, Encoding.UTF8);
                data = Encoding.UTF8.GetBytes(s);
            }
            unityWebRequest.uploadHandler             = new UploadHandlerRaw(data);
            unityWebRequest.uploadHandler.contentType = "application/x-www-form-urlencoded";
            unityWebRequest.downloadHandler           = new DownloadHandlerBuffer();
            return(unityWebRequest);
        }