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
注入
使用