使用json正文请求使用Rest Webservice
这个问题在这里已经有了答案:
你必须使用StreamWriter
和StreamReader
。
var httpWebRequest = (HttpWebRequest)WebRequest.Create(tb_URL.Text);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{"lastName": "Jordan", "firstName": "Michael"}";
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
链接地址: http://www.djcxy.com/p/45865.html