MVCバックグラウンドPOSTメソッド呼び出しリモートAPIインタフェース
//post
public void PostFunction(string devID)
{
string url = "";// URL
string strPostdata = "{\"id\":\"rt02\"}";// !
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "post";
request.ContentType = "application/json";
byte[] buffer = encoding.GetBytes(strPostdata);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var res = "";
using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")))
{
res = reader.ReadToEnd();//
}
}
, ,alt + shift + F10 。
:
using System.IO;
using System.Net;
using System.Text;