My Spring Boot server returns 406 Http error code





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a Spring Boot server application that receives a POST request from an external service with the following characteristics:



Headers



accept-encoding: gzip,deflate



user-agent: Apache-HttpClient/4.3.6 (java 1.5)



connection: Keep-Alive



host: webhook.site



content-type: application/x-www-form-urlencoded



content-length: 558



Query strings:(empty)



Form values



BillNumber: 41492032464



BillValue: 600000.0



Description: Description



To be able to handle this POST request from the external service I implemented the following controller, which what it does is create and store an invoice, but my application returns an HTTP Error 406:



@RequestMapping(value = "/bills", method = RequestMethod.POST, headers = "Accept=application/x-www-form-urlencoded")
@ResponseBody
@Transactional
public void createBill(UriComponentsBuilder uriComponentsBuilder, final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
}


I understand that the error refers to the client (in this case the external service) does not understand the "language" of the server response, but as you can see in the headers of my controller I am accepting "application / x-www-form -urlencoded "I do not know if it's due to another problem also my controller it's void



How should this controller be implemented in my spring boot app?



Many Thanks!










share|improve this question


















  • 1





    No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

    – jonrsharpe
    Nov 16 '18 at 12:46


















0















I have a Spring Boot server application that receives a POST request from an external service with the following characteristics:



Headers



accept-encoding: gzip,deflate



user-agent: Apache-HttpClient/4.3.6 (java 1.5)



connection: Keep-Alive



host: webhook.site



content-type: application/x-www-form-urlencoded



content-length: 558



Query strings:(empty)



Form values



BillNumber: 41492032464



BillValue: 600000.0



Description: Description



To be able to handle this POST request from the external service I implemented the following controller, which what it does is create and store an invoice, but my application returns an HTTP Error 406:



@RequestMapping(value = "/bills", method = RequestMethod.POST, headers = "Accept=application/x-www-form-urlencoded")
@ResponseBody
@Transactional
public void createBill(UriComponentsBuilder uriComponentsBuilder, final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
}


I understand that the error refers to the client (in this case the external service) does not understand the "language" of the server response, but as you can see in the headers of my controller I am accepting "application / x-www-form -urlencoded "I do not know if it's due to another problem also my controller it's void



How should this controller be implemented in my spring boot app?



Many Thanks!










share|improve this question


















  • 1





    No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

    – jonrsharpe
    Nov 16 '18 at 12:46














0












0








0








I have a Spring Boot server application that receives a POST request from an external service with the following characteristics:



Headers



accept-encoding: gzip,deflate



user-agent: Apache-HttpClient/4.3.6 (java 1.5)



connection: Keep-Alive



host: webhook.site



content-type: application/x-www-form-urlencoded



content-length: 558



Query strings:(empty)



Form values



BillNumber: 41492032464



BillValue: 600000.0



Description: Description



To be able to handle this POST request from the external service I implemented the following controller, which what it does is create and store an invoice, but my application returns an HTTP Error 406:



@RequestMapping(value = "/bills", method = RequestMethod.POST, headers = "Accept=application/x-www-form-urlencoded")
@ResponseBody
@Transactional
public void createBill(UriComponentsBuilder uriComponentsBuilder, final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
}


I understand that the error refers to the client (in this case the external service) does not understand the "language" of the server response, but as you can see in the headers of my controller I am accepting "application / x-www-form -urlencoded "I do not know if it's due to another problem also my controller it's void



How should this controller be implemented in my spring boot app?



Many Thanks!










share|improve this question














I have a Spring Boot server application that receives a POST request from an external service with the following characteristics:



Headers



accept-encoding: gzip,deflate



user-agent: Apache-HttpClient/4.3.6 (java 1.5)



connection: Keep-Alive



host: webhook.site



content-type: application/x-www-form-urlencoded



content-length: 558



Query strings:(empty)



Form values



BillNumber: 41492032464



BillValue: 600000.0



Description: Description



To be able to handle this POST request from the external service I implemented the following controller, which what it does is create and store an invoice, but my application returns an HTTP Error 406:



@RequestMapping(value = "/bills", method = RequestMethod.POST, headers = "Accept=application/x-www-form-urlencoded")
@ResponseBody
@Transactional
public void createBill(UriComponentsBuilder uriComponentsBuilder, final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
}


I understand that the error refers to the client (in this case the external service) does not understand the "language" of the server response, but as you can see in the headers of my controller I am accepting "application / x-www-form -urlencoded "I do not know if it's due to another problem also my controller it's void



How should this controller be implemented in my spring boot app?



Many Thanks!







java spring spring-boot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 12:44









AlejoDevAlejoDev

389525




389525








  • 1





    No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

    – jonrsharpe
    Nov 16 '18 at 12:46














  • 1





    No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

    – jonrsharpe
    Nov 16 '18 at 12:46








1




1





No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

– jonrsharpe
Nov 16 '18 at 12:46





No, it means that the server can't generate what the client is asking for. You're mixing up Accept (here's what I want back) and Content-Type (here's what I'm sending) headers.

– jonrsharpe
Nov 16 '18 at 12:46












1 Answer
1






active

oldest

votes


















1














You should use consumes with MediaType to define the supported Content-Type. You can further simplify by using @PostMapping:



@PostMapping(value = "/bills", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)


It's pointless to set Accept header on response like you do now, this is a request header. As per Mozilla docs:




The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.







share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338185%2fmy-spring-boot-server-returns-406-http-error-code%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You should use consumes with MediaType to define the supported Content-Type. You can further simplify by using @PostMapping:



    @PostMapping(value = "/bills", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)


    It's pointless to set Accept header on response like you do now, this is a request header. As per Mozilla docs:




    The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.







    share|improve this answer




























      1














      You should use consumes with MediaType to define the supported Content-Type. You can further simplify by using @PostMapping:



      @PostMapping(value = "/bills", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)


      It's pointless to set Accept header on response like you do now, this is a request header. As per Mozilla docs:




      The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.







      share|improve this answer


























        1












        1








        1







        You should use consumes with MediaType to define the supported Content-Type. You can further simplify by using @PostMapping:



        @PostMapping(value = "/bills", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)


        It's pointless to set Accept header on response like you do now, this is a request header. As per Mozilla docs:




        The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.







        share|improve this answer













        You should use consumes with MediaType to define the supported Content-Type. You can further simplify by using @PostMapping:



        @PostMapping(value = "/bills", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)


        It's pointless to set Accept header on response like you do now, this is a request header. As per Mozilla docs:




        The Accept request HTTP header advertises which content types, expressed as MIME types, the client is able to understand. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Type response header. Browsers set adequate values for this header depending on the context where the request is done: when fetching a CSS stylesheet a different value is set for the request than when fetching an image, video or a script.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 12:51









        Karol DowbeckiKarol Dowbecki

        26.4k93759




        26.4k93759
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53338185%2fmy-spring-boot-server-returns-406-http-error-code%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly