when I call get
and delete
method it works ok when I call Add
method browser console shows errors.
here is code I am using for cors
in service configuration
services.AddCors();
and in app builder
app.UseCors(b => b.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod());
app.UseMvc();
Service code
@Injectable({
providedIn: 'root'
})
export class PropertyService {
readonly rootUrl = 'http://localhost:5867';
selectedPost : Post;
PostList : Post[];
constructor(private http : Http) { }
PostUserProperty( _newpost : Post ){
var body = JSON.stringify(_newpost);
var headerOptions = new Headers({'Content-Type' : 'application/json'});
var requestOption = new RequestOptions({method : RequestMethod.Post, headers : headerOptions });
return this.http.post(this.rootUrl + '/api/AddUserProperties', body , requestOption).map(response => response.json());
} }
api controller Post method
// POST: api/UserProperties
[Route("~/api/AddUserProperties")]
[HttpPost]
public async Task<IActionResult> PostUserProperty([FromBody] UserProperty userProperty)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_context.UserProperty.Add(userProperty);
await _context.SaveChangesAsync();
return CreatedAtAction("GetUserProperty", new { id = userProperty.PropertyId }, userProperty);
}
and this is what ASP.NET SERVER Showing in console
RealEstateApis> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
RealEstateApis> Request starting HTTP/1.1 OPTIONS http://localhost:5867/api/AddUserProperties
RealEstateApis> info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
RealEstateApis> Policy execution successful.
RealEstateApis> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
RealEstateApis> Request finished in 4370.8769ms 204
RealEstateApis> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
RealEstateApis> Request starting HTTP/1.1 POST http://localhost:5867/api/AddUserProperties application/json 282
RealEstateApis> info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
RealEstateApis> Policy execution successful.
RealEstateApis> info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
RealEstateApis> Executing action method RealEstateApis.Controllers.UserPropertiesController.PostUserProperty (RealEstateApis) with arguments (RealEstateApis.Models.UserProperty) - ModelState is Valid
RealEstateApis> info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
RealEstateApis> Entity Framework Core 2.0.3-rtm-10026 initialized 'realestateContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: None
RealEstateApis> fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
RealEstateApis> Failed executing DbCommand (430ms) [Parameters=[@p0='?', @p1='?' (Size
= 45), @p2='?', @p3='?', @p4='?' (Size = 45), @p5='?', @p6='?', @p7='?' (Size = 255), @p8='?' (Size = 45), @p9='?' (Size = 45), @p10='?', @p11='?' (Size = 45), @p12='?' (Size = 45), @p13='?' (Size = 45), @p14='?' (Size = 45), @p15='?'], CommandType='Text', CommandTimeout='30']
RealEstateApis> INSERT INTO `user_property` (`property_id`, `address`, `bathroom`, `bedroom`, `country`, `description`, `expire_on`, `image_url`, `land_area`, `price`, `property_type_id`, `purpose`, `region`, `services_in_area`, `unit`, `user_id`)
RealEstateApis> VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15);
RealEstateApis> MySql.Data.MySqlClient.MySqlException (0x80004005): Column 'image_url' cannot be null ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Column 'image_url' cannot be null
RealEstateApis> at MySqlConnector.Protocol.PayloadData.ThrowIfError() in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\PayloadData.cs:line 19
RealEstateApis> at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 870
RealEstateApis> at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
RealEstateApis> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
RealEstateApis> at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
RealEstateApis> at MySqlConnector.Core.ResultSet.<ReadResultSetHeaderAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 92
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__65.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 297
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__64.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 287
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 70
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
RealEstateApis> fail: Microsoft.EntityFrameworkCore.Update[10000]
RealEstateApis> An exception occurred in the database while saving changes for context type 'RealEstateApis.Models.realestateContext'.
RealEstateApis> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null
RealEstateApis> at MySqlConnector.Protocol.PayloadData.ThrowIfError() in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\PayloadData.cs:line 19
RealEstateApis> at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 870
RealEstateApis> at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
RealEstateApis> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
RealEstateApis> at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
RealEstateApis> at MySqlConnector.Core.ResultSet.<ReadResultSetHeaderAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
RealEstateApis> --- End of inner exception stack trace ---
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 92
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__65.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 297
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__64.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 287
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 70
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__2.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext()
RealEstateApis> --- End of inner exception stack trace ---
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.Internal.MySqlBatchExecutor.<ExecuteAsync>d__1.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__61.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__59.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.DbContext.<SaveChangesAsync>d__48.MoveNext()
RealEstateApis> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null
RealEstateApis> at MySqlConnector.Protocol.PayloadData.ThrowIfError() in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\PayloadData.cs:line 19
RealEstateApis> at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 870
RealEstateApis> at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
RealEstateApis> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
RealEstateApis> at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
RealEstateApis> at MySqlConnector.Core.ResultSet.<ReadResultSetHeaderAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
RealEstateApis> --- End of inner exception stack trace ---
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 92
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__65.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 297
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__64.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 287
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 70
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__2.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext()
RealEstateApis> --- End of inner exception stack trace ---
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.<ExecuteAsync>d__32.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at Microsoft.EntityFrameworkCore.Update.Internal.MySqlBatchExecutor.<ExecuteAsync>d__1.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__61.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<SaveChangesAsync>d__59.MoveNext()
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
RealEstateApis> at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
RealEstateApis> at Microsoft.EntityFrameworkCore.DbContext.<SaveChangesAsync>d__48.MoveNext()
RealEstateApis> info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
RealEstateApis> Executed action RealEstateApis.Controllers.UserPropertiesController.PostUserProperty (RealEstateApis) in 20873.3858ms
RealEstateApis> fail: Microsoft.AspNetCore.Server.Kestrel[13]
RealEstateApis> Connection id "0HLG20PKTM082", Request id "0HLG20PKTM082:00000002": An unhandled exception was thrown by the application.
RealEstateApis> Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null ---> MySql.Data.MySqlClient.MySqlException: Column 'image_url' cannot be null
RealEstateApis> at MySqlConnector.Protocol.PayloadData.ThrowIfError() in C:\projects\mysqlconnector\src\MySqlConnector\Protocol\PayloadData.cs:line 19
RealEstateApis> at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task`1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 870
RealEstateApis> at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
RealEstateApis> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
RealEstateApis> at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
RealEstateApis> --- End of stack trace from previous location where exception was thrown ---
RealEstateApis> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
RealEstateApis>
Column 'image_url' cannot be null ---> MySql.Data.MySqlClient.MySqlException (0x80004005):
As a guide to what to look in the error wall of text, search for "inner exception"
User contributions licensed under CC BY-SA 3.0