Android http发布到ASP.NET Web API不会插入数据

【Android http发布到ASP.NET Web API不会插入数据】万事须己运,他得非我贤。这篇文章主要讲述Android http发布到ASP.NET Web API不会插入数据相关的知识,希望能为你提供帮助。
我正在使用android。我想将数据发布到ASP.NET Web API。我使用以下方法尝试了http post

HttpPost httpPost = new HttpPost(url); httpPost.setHeader("content-type", "application/json"); httpPost.setHeader("Accept", "application/json"); // adding post params if (params != null) { httpPost.setEntity(new UrlEncodedFormEntity(params)); }Log.i("serrrrr",""+params); httpResponse = httpClient.execute(httpPost);

我的名字对看起来像
[attendance={"attendance_id":"0","Usr_Id":"5","Com_Id":"1","date":"12-11-2015","time_in":"04:41:41 pm","time_out":"","location_in":"my address","location_out":"","status_in":"true","status_out":"true","total_time":"","App_id":"1"}]

当我试图将此数据发布到web api时,我收到以下错误
{“Message”:“发生错误。”,“ExceptionMessage”:“对象引用未设置为对象的实例。”,“ExceptionType”:“System.NullReferenceException”,“StackTrace”:“at WebApplication.Areas在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor。< > c__DisplayClass10.b__9的lambda_method(Closure,Object,Object []) rn的.Json.Controllers.AttendancesController.PostAttendance(出勤出勤) rn( System.Web.Http.Controllers.ReflectedHttpActionDescriptor中的System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance,Object [] arguments) rn的对象实例,Object [] methodParameters) rn。 ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken cancellationToken) rn ---从抛出异常的上一个位置开始的堆栈跟踪结束---rn在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务)任务) rn在System.Runtime.CompilerServices.TaskAwaiter.HandleN onSuccessAndDebuggerNotification(任务任务) rn在System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext() rn ---从前一个引发异常的位置的堆栈跟踪结束---rn at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) rn在System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) rn中() rn ---从抛出异常的上一个位置开始的堆栈跟踪结束---在System.Runtime的System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) rn中的 rn。 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()“}中的CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) rn
我该如何解决这个问题?发送参数有什么问题吗?
答案你的榜样
[ attendance={ "attendance_id":"0", "Usr_Id":"5", "Com_Id":"1", "date":"12-11-2015", "time_in":"04:41:41 pm", "time_out":"", "location_in":"my address", "location_out":"", "status_in":"true", "status_out":"true", "total_time":"", "App_id":"1" } ]

是无效的JSON,因为您在数组中有一个键值对。你可以在http://jsonlint.com/上查看
因此,您的输入/ postdata无法反序列化,并且服务器端代码不执行错误处理来捕获它(并且可选地返回有意义的错误消息)。
修正你的输入。

    推荐阅读