1 string postData = "appKey=" + appKey;//參數 2 postData += ("&appSecret=" + appSecret); 3 4 var request = (HttpWebRequest)WebRequest.Create(url); 5 req ...
1 string postData = "appKey=" + appKey;//參數 2 postData += ("&appSecret=" + appSecret); 3 4 var request = (HttpWebRequest)WebRequest.Create(url); 5 request.Method = "POST";//請求方式 6 request.ContentType = "application/x-www-form-urlencoded";//請求內容類型 7 var data = Encoding.UTF8.GetBytes(postData);//獲取長度 8 request.ContentLength = data.Length; 9 Stream newStream = request.GetRequestStream(); 10 11 //send 12 newStream.Write(data, 0, data.Length); 13 newStream.Close(); 14 15 //get 16 WebResponse response = request.GetResponse(); 17 newStream = response.GetResponseStream(); 18 StreamReader reader = new StreamReader(newStream); 19 string responseFromServer = reader.ReadToEnd();//得到返回數據 20 reader.Close(); 21 response.Close();