/// <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=" + "這是音頻內容");