当我试图通过小提琴手来测试我的HTTP后我MVC4的WebAPI让我在第一如果条件正在检查smsReq.Body空指针引用错误的权利。 该SMSREQ即将为NULL。 我究竟做错了什么?
这是我的POST方法和提琴手请求。 我使用MVC4网络API
using System.Web.Http;
using System.Web;
using Twilio.TwiML.Mvc;
using Twilio.Mvc;
public class ValuesController : ApiController
{
[HttpPost]
public HttpResponseMessage Postsms([FromBody]SmsRequest smsReq)
{
if (String.IsNullOrEmpty(smsReq.Body.ToString()))
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));
}
else
{
string smsTextType = smsReq.Body.ToString();
HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.Created, "Hello World");
return response;
}
这是我的帖子看起来就像小提琴手:
User-Agent: Fiddler
Content-Type: application/json; charset=utf-8
Accept: application/xml
SmsSid: xxxx
AccountSid: xxxxx
From: xxxx
To: xxxx
Host: localhost:9999
Content-Length: 5
Body: abc