從SERVER後端發送Http Resqust語法
以JSON範例
//參數
string data = "{\"data\":[{ \"name\": \"Mark\", \"sex\": \"man\" },{ \"name\": \"Sara\", \"sex\": \"woman\" }]}";
//建立httpWebRequest
var httpWebRequest = (HttpWebRequest)WebRequest.Create("URL");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
try
{
using (var RequestWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
RequestWriter.Write(data);
RequestWriter.Flush();
RequestWriter.Close();
}
//將SERVER回傳的資料序列化使用
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var RequestReader = new StreamReader(httpResponse.GetResponseStream()))
{
var json_result = RequestReader.ReadToEnd();
Message result = JsonConvert.DeserializeObject<Message>(json_result);
}
}
catch
{
}
以上內容,若有錯誤
煩請各路高手路過指正
謝謝!
<(_ _)>