Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Web Api POST #270


User avatar
0
sasailic created

GET Requests works correctly, but when i try to post something i get "message=An internal error occurred during your request!" Error. This code works correctly MVC Web Api project, but not works on boilerplate.

public HttpResponseMessage Post(Contact contact)
        {
            contactRepository.SaveContact(contact);

            var response = Request.CreateResponse(HttpStatusCode.Created, contact);

            return response;
        }

6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Have you checked logs in web project's logs folder?

  • User Avatar
    0
    sasailic created

    Yes but I couldn't find anything :|

    I attached my log file, I cleaned up it before restart project. Logs.rar

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    It seems there is a JSON serialization problem. I think Contact is an entity. If so, returning entities may have serialization problems. Instead, we use DTOs (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Transfer-Objects">http://www.aspnetboilerplate.com/Pages/ ... er-Objects</a>). Also, you can add an Exception Handler to your project to catch the exception and check it in details (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Handling-Exceptions#DocExceptionEvent">http://www.aspnetboilerplate.com/Pages/ ... ptionEvent</a>)

  • User Avatar
    0
    sasailic created

    It doesn't work :cry: Do you have a sample for POST request working on boiler template?

  • User Avatar
    0
    sasailic created

    Exception Handler returns this error message: "Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details."

  • User Avatar
    0
    hikalkan created
    Support Team

    Have you added exception event handler and checked the exception deeply? (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Handling-Exceptions#DocExceptionEvent">http://www.aspnetboilerplate.com/Pages/ ... ptionEvent</a>)

    Do you have a sample for POST request working on boiler template

    Surely, sample applications does it. Example: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/SimpleTaskSystem">https://github.com/aspnetboilerplate/as ... TaskSystem</a>