问题描述
这是我第一次调用put API时遇到的麻烦。我正在尝试通过使用https的API来更新配置文件。 该API在邮递员中正常运行,但在模拟器内部,它返回错误代码500。我还在标题中添加了内容类型:“ application / json”。 请帮助我解决问题。
class ProfileRepo {
static const API = 'https://ramu.sdaemon.com/api/';
//Customer/PuttblMstCustomer
Future<ProfileModelResponse> putProfile(
ProfileModelRequest profileModelRequest) async {
print(profileModelRequest);
log('data : ${profileModelRequest.toString()}');
var requestEncoded = jsonEncode(profileModelRequest);
var jsonvalue = jsonEncode({
"CustomerID": 12,"FirstName": "Akshay","LastName": "","CompanyID": "","HomeAddress": "","OfficeAddress": "","FromOfficeTime": "","ToOfficeTime": "","City": "","CountryID": "","PostalCode": "","PhoneNo": "8805078548","AlternativePhoneNo": "","Birthdate": "","Email": "","AddedBy": "","AddedOn": "","ModifiedBy": "","ModifiedOn": "","CompanyName": "","CountryName": ""
});
final result = await http.Client().put(API + 'Customer/PuttblMstCustomer/',body: jsonvalue,headers: {
"Accept": "application/json","Content-Type": "application/json"
});
log(result.body.toString());
print(result.body.toString());
if (result.statusCode != 200){
/* Fluttertoast.showToast(
msg: "API fail",toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.CENTER,timeInSecForIosWeb: 1,backgroundColor: Colors.red,textColor: Colors.white,fontSize: 16.0);*/
throw Exception();
}else{
Fluttertoast.showToast(
msg: "API Success",fontSize: 16.0);
}
return parsedJson(result.body);
}
ProfileModelResponse parsedJson(final response){
final jsonDecoded = jsonDecode(response);
return ProfileModelResponse.fromJson(jsonDecoded);
}
}
print(result.body.toString())
在下面给出了输出
{"Message":"An error has occurred.","ExceptionMessage":"Store update,insert,or delete
statement affected an unexpected number of rows (0). Entities may have been modified or
deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for
@R_186_4045@ion on understanding and handling optimistic concurrency exceptions.","ExceptionType":"System.Data.Entity.Infrastructure.dbupdateConcurrencyException","StackTrace":" at System.Data.Entity.Internal.InternalContext.SaveChanges()\r\n at
System.Data.Entity.Internal.LazyInternalContext.SaveChanges()\r\n at
System.Data.Entity.DbContext.SaveChanges()\r\n at
BusinessLogic.Models.CommonClasses.ClsCustomer.Edit(tblMstCustomer customer) in
D:\\Sdaemon\\EcommerceCRM\\BusinessLogic\\Models\\CommonClasses\\ClsCustomer.cs:line 99\r\n
at EcommerceCRMAPI.Controllers.CustomerController.PuttblMstCustomer(tblMstCustomer Customer)
in D:\\Sdaemon\\EcommerceCRM\\EcommerceCRMAPI\\Controllers\\CustomerController.cs:line
105\r\n at lambda_method(Closure,Object,Object[] )\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor
.<>c__displayClass6_1.<GetExecutor>b__3(Object instance,Object[] methodParameters)\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object
instance,Object[] arguments)\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext
controllerContext,IDictionary`2 arguments,CancellationToken cancellationToken)\r\n--- End
of stack trace from prevIoUs location where exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker
.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from prevIoUs location where
exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at System.Web.Http.Controllers.ActionFilterResult
.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from prevIoUs location where
exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult
.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from prevIoUs location where
exception was thrown ---\r\n at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)\r\n at System.Web.Http.dispatcher.HttpControllerdispatcher
.<SendAsync>d__15.MoveNext()","InnerException":{"Message":"An error has
occurred.",or delete statement affected an
unexpected number of rows (0). Entities may have been modified or deleted since entities were
loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for @R_186_4045@ion on understanding
and handling optimistic concurrency exceptions.","ExceptionType":"System.Data.Entity.Core.OptimisticConcurrencyException","StackT
race":" at
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64
rowsAffected,UpdateCommand source)\r\n at
System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()\r\n at
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator
ut)\r\n at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T
noChangesResult,Func`2 updateFunction)\r\n at
System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()\r\n at
System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()\r\n at
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean
releaseConnectionOnSuccess)\r\n at
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options,Boolean startLocalTransaction)\r\n at
System.Data.Entity.Core.Objects.ObjectContext.<>c__displayClass2a
.<SaveChangesInternal>b__27()\r\n at
System.Data.Entity.sqlServer.DefaultsqlExecutionStrategy.Execute[TResult](Func`1
operation)\r\n at
System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options,Boolean executeInExistingTransaction)\r\n at
System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)\r\n at
System.Data.Entity.Internal.InternalContext.SaveChanges()"}}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)