Post utf-8 请求
/// <summary> /// POST请求与获取结果 /// </summary> public static string HttpPost(string Url, string postDataStr) { //把数组转换成流中所需字节数组类型 Encoding code = Encoding.GetEncoding("utf-8"); byte[] bytesRequestData = code.GetBytes(postDataStr); //设置HttpWebRequest基本信息 HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(Url); myReq.Method = "post"; myReq.ContentType = "application/x-www-form-urlencoded"; //填充POST数据 myReq.ContentLength = bytesRequestData.Length; Stream requestStream = myReq.GetRequestStream(); requestStream.Write(bytesRequestData, 0, bytesRequestData.Length); requestStream.Close(); //发送POST数据请求服务器 HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse(); //接收对应的流 StreamReader reader = new StreamReader(HttpWResp.GetResponseStream()); string retString = reader.ReadToEnd(); return retString; }
--调用
var result = HttpPost(sendUrl, "id=1&text=" + "这是音频内容");