C# httpPost

 

1.

        private string HttpPost(string postDataStr)
        {
            string Url = "http://47.92.38.124:8003/api/ServerSignApi/ApplyStamp";
            WebRequest request = WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/json";
            byte[] buf = Encoding.UTF8.GetBytes(postDataStr);
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(postDataStr);
            request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
            request.GetRequestStream().Write(buf, 0, buf.Length);
            WebResponse response = request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

2.引入HttpClient

C# httpPost_第1张图片

注入

C# httpPost_第2张图片

使用

 

 

 

httpClint使用看大佬的:wzk153

 

转载于:https://www.cnblogs.com/Cein/p/11169720.html

你可能感兴趣的:(C# httpPost)