您的足迹:首页 > .NET >C# post 接口

C# post 接口

   public string HttpPostImg(string imagebase64, string name)
        {

           // string url = "http://localhost:5012/ocr/base64";
            string url = REQ_URL;
            model m = new model();
            m.img_b64 = imagebase64;
            m.img_Name = name;

           string jsonParam = JsonConvert.SerializeObject(m);
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/json;charset=UTF-8";
            byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
            int length = byteData.Length;
            request.ContentLength = length;
            Stream writer = request.GetRequestStream();
            writer.Write(byteData, 0, length);
            writer.Close();
            var response = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
            return responseString;
        }
本博客所有文章如无特别注明均为原创。作者:cc复制或转载请以超链接形式注明转自 .NET程序员之路
原文地址《C# post 接口

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)