unity3d:WebRequest post请求

2023-08-24 15:03:23 浏览数 (1)

命名空间using System.Net;

代码语言:javascript复制
        public static string GetResponse(string reqString)
        {
            string result = "";
            WebRequest req = WebRequest.Create(reqString);
            req.ContentType = "text/html; charset=UTF-8";

            WebResponse res = req.GetResponse();
            Stream stream = res.GetResponseStream();

            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))//Encoding.GetEncoding("gb2312")
            {
                result = reader.ReadToEnd();
            }
            return result;
        }

0 人点赞