読者です 読者をやめる 読者になる 読者になる

C#でREST通信時、BODYにデータを入れる方法

C#

GetRequestStream()を使う

HttpWebRequest HttpWReq =
(HttpWebRequest)WebRequest.Create("http:\\domain.com\page.asp");

ASCIIEncoding encoding=new ASCIIEncoding();
string stringData = ""; //place body here
byte[] data = encoding.GetBytes(stringData);

HttpWReq.Method = "PUT";
HttpWReq.ContentType = ""; //place MIME type here
HttpWReq.ContentLength = data.Length;

Stream newStream = HttpWReq.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();

ネタ元