frombody null
我的webapi:public string Post([FromBody]string value)
{
// string order = value.ToString();
/*
if (value == "8888")
{
return hotel;
}
else if(value == null) {
return null;
}
return hotel;
// return hotel;
//return null;
*/
return value;
}
我的post winform程序:
string reqestMsg = "8888";
string responseMsg = string.Empty;
byte[] buffer = Encoding.UTF8.GetBytes(reqestMsg);
string url = textBox2.Text;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = buffer.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(buffer, 0, buffer.Length);
}
HttpWebResponse resonse = (HttpWebResponse)request.GetResponse();
Stream responseStream = resonse.GetResponseStream();
using (StreamReader sr = new StreamReader(responseStream))
{
responseMsg = sr.ReadToEnd();
textBox1.Text = responseMsg;
}
resonse.Close();
}
//textbox2.text = "http://localhost:50828/api/gethotellist/";
这个样子,但是传递过去的返回值 一直为NULL,就是传递参数 赋值不了value~求救!!!!