Server can't parse something in ajax post parameter, what is causing this?












0














I'm making an ajax post request, and i can see the value is being passed in the headers on the client side.



However on the server side the value received is blank? The server seems to be choking on something in the value when it tries to parse it. Because if i use encodeURIComponent it works fine. What is causing this behaviour?



<script>

//var body = getDataFromTheEditor(); //doesn't work
//var body = JSON.stringify(getDataFromTheEditor()); //doesn't work
var body = encodeURIComponent(getDataFromTheEditor()); //works but don't want to do this...

var params = {body: body};
$.post("../../../../CommitEdit", $.param(params));

</script>


Servlet:



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String body = request.getParameter("body");
System.out.println(body); //blank if i pass it normally :(

}


I've copied the formdata directly from the header as it is being passed (so there's something in here which the server doesn't like apparently):



pastebin - unparsed formdata



pastebin - parsed formdata



Relevant request headers:



Content-Length: 64488
Content-Type: application/x-www-form-urlencoded; charset=UTF-8


Any ideas? Thanks.










share|improve this question






















  • System.out.println(body); gives you a blank (empty String) or null?
    – Roshana Pitigala
    Nov 10 at 17:26












  • blank value is being passed
    – Jonathan Laliberte
    Nov 10 at 17:30






  • 1




    No repo. I'm getting the full text from the server side without encoding.
    – Roshana Pitigala
    Nov 10 at 17:49












  • hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
    – Jonathan Laliberte
    Nov 10 at 17:58










  • Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
    – Roshana Pitigala
    Nov 10 at 18:08


















0














I'm making an ajax post request, and i can see the value is being passed in the headers on the client side.



However on the server side the value received is blank? The server seems to be choking on something in the value when it tries to parse it. Because if i use encodeURIComponent it works fine. What is causing this behaviour?



<script>

//var body = getDataFromTheEditor(); //doesn't work
//var body = JSON.stringify(getDataFromTheEditor()); //doesn't work
var body = encodeURIComponent(getDataFromTheEditor()); //works but don't want to do this...

var params = {body: body};
$.post("../../../../CommitEdit", $.param(params));

</script>


Servlet:



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String body = request.getParameter("body");
System.out.println(body); //blank if i pass it normally :(

}


I've copied the formdata directly from the header as it is being passed (so there's something in here which the server doesn't like apparently):



pastebin - unparsed formdata



pastebin - parsed formdata



Relevant request headers:



Content-Length: 64488
Content-Type: application/x-www-form-urlencoded; charset=UTF-8


Any ideas? Thanks.










share|improve this question






















  • System.out.println(body); gives you a blank (empty String) or null?
    – Roshana Pitigala
    Nov 10 at 17:26












  • blank value is being passed
    – Jonathan Laliberte
    Nov 10 at 17:30






  • 1




    No repo. I'm getting the full text from the server side without encoding.
    – Roshana Pitigala
    Nov 10 at 17:49












  • hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
    – Jonathan Laliberte
    Nov 10 at 17:58










  • Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
    – Roshana Pitigala
    Nov 10 at 18:08
















0












0








0







I'm making an ajax post request, and i can see the value is being passed in the headers on the client side.



However on the server side the value received is blank? The server seems to be choking on something in the value when it tries to parse it. Because if i use encodeURIComponent it works fine. What is causing this behaviour?



<script>

//var body = getDataFromTheEditor(); //doesn't work
//var body = JSON.stringify(getDataFromTheEditor()); //doesn't work
var body = encodeURIComponent(getDataFromTheEditor()); //works but don't want to do this...

var params = {body: body};
$.post("../../../../CommitEdit", $.param(params));

</script>


Servlet:



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String body = request.getParameter("body");
System.out.println(body); //blank if i pass it normally :(

}


I've copied the formdata directly from the header as it is being passed (so there's something in here which the server doesn't like apparently):



pastebin - unparsed formdata



pastebin - parsed formdata



Relevant request headers:



Content-Length: 64488
Content-Type: application/x-www-form-urlencoded; charset=UTF-8


Any ideas? Thanks.










share|improve this question













I'm making an ajax post request, and i can see the value is being passed in the headers on the client side.



However on the server side the value received is blank? The server seems to be choking on something in the value when it tries to parse it. Because if i use encodeURIComponent it works fine. What is causing this behaviour?



<script>

//var body = getDataFromTheEditor(); //doesn't work
//var body = JSON.stringify(getDataFromTheEditor()); //doesn't work
var body = encodeURIComponent(getDataFromTheEditor()); //works but don't want to do this...

var params = {body: body};
$.post("../../../../CommitEdit", $.param(params));

</script>


Servlet:



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String body = request.getParameter("body");
System.out.println(body); //blank if i pass it normally :(

}


I've copied the formdata directly from the header as it is being passed (so there's something in here which the server doesn't like apparently):



pastebin - unparsed formdata



pastebin - parsed formdata



Relevant request headers:



Content-Length: 64488
Content-Type: application/x-www-form-urlencoded; charset=UTF-8


Any ideas? Thanks.







java ajax servlets form-data






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 17:16









Jonathan Laliberte

1,6042824




1,6042824












  • System.out.println(body); gives you a blank (empty String) or null?
    – Roshana Pitigala
    Nov 10 at 17:26












  • blank value is being passed
    – Jonathan Laliberte
    Nov 10 at 17:30






  • 1




    No repo. I'm getting the full text from the server side without encoding.
    – Roshana Pitigala
    Nov 10 at 17:49












  • hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
    – Jonathan Laliberte
    Nov 10 at 17:58










  • Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
    – Roshana Pitigala
    Nov 10 at 18:08




















  • System.out.println(body); gives you a blank (empty String) or null?
    – Roshana Pitigala
    Nov 10 at 17:26












  • blank value is being passed
    – Jonathan Laliberte
    Nov 10 at 17:30






  • 1




    No repo. I'm getting the full text from the server side without encoding.
    – Roshana Pitigala
    Nov 10 at 17:49












  • hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
    – Jonathan Laliberte
    Nov 10 at 17:58










  • Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
    – Roshana Pitigala
    Nov 10 at 18:08


















System.out.println(body); gives you a blank (empty String) or null?
– Roshana Pitigala
Nov 10 at 17:26






System.out.println(body); gives you a blank (empty String) or null?
– Roshana Pitigala
Nov 10 at 17:26














blank value is being passed
– Jonathan Laliberte
Nov 10 at 17:30




blank value is being passed
– Jonathan Laliberte
Nov 10 at 17:30




1




1




No repo. I'm getting the full text from the server side without encoding.
– Roshana Pitigala
Nov 10 at 17:49






No repo. I'm getting the full text from the server side without encoding.
– Roshana Pitigala
Nov 10 at 17:49














hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
– Jonathan Laliberte
Nov 10 at 17:58




hmm looks like i am getting something, but the string is cut off and there's an abnormally long amount of blank space before it (so it looked like it was just blank) but had to scroll horizontally. Are you getting that?
– Jonathan Laliberte
Nov 10 at 17:58












Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
– Roshana Pitigala
Nov 10 at 18:08






Yeah there's a blank space in front of the text. I can confirm that. But I got from <p> to </p>. I didn't check the middle part though.
– Roshana Pitigala
Nov 10 at 18:08














2 Answers
2






active

oldest

votes


















0














It maybe caused because of some security rules in the web server settings.
You can decode your data in Java using this:



String res= java.net.URLDecoder.decode(body, "UTF-8");





share|improve this answer























  • Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
    – Jonathan Laliberte
    Nov 10 at 17:32



















0














The problem was because the string was too long. Apparently the console in Eclipse has a character limit. Which is why i was seeing a blank value. This question here helped solve the issue:



Character limit for System.out.println() in Java



The solution is to:





  1. Go to Window > Preferences > Run/Debug > Console

  2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)







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%2f53241449%2fserver-cant-parse-something-in-ajax-post-parameter-what-is-causing-this%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It maybe caused because of some security rules in the web server settings.
    You can decode your data in Java using this:



    String res= java.net.URLDecoder.decode(body, "UTF-8");





    share|improve this answer























    • Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
      – Jonathan Laliberte
      Nov 10 at 17:32
















    0














    It maybe caused because of some security rules in the web server settings.
    You can decode your data in Java using this:



    String res= java.net.URLDecoder.decode(body, "UTF-8");





    share|improve this answer























    • Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
      – Jonathan Laliberte
      Nov 10 at 17:32














    0












    0








    0






    It maybe caused because of some security rules in the web server settings.
    You can decode your data in Java using this:



    String res= java.net.URLDecoder.decode(body, "UTF-8");





    share|improve this answer














    It maybe caused because of some security rules in the web server settings.
    You can decode your data in Java using this:



    String res= java.net.URLDecoder.decode(body, "UTF-8");






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 10 at 17:34

























    answered Nov 10 at 17:28









    Majid

    7,81085599




    7,81085599












    • Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
      – Jonathan Laliberte
      Nov 10 at 17:32


















    • Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
      – Jonathan Laliberte
      Nov 10 at 17:32
















    Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
    – Jonathan Laliberte
    Nov 10 at 17:32




    Yes i know how to decode the encoded string, but i'm interested in knowing why this is happening. And why i can't just pass it without encoding it like any other string.
    – Jonathan Laliberte
    Nov 10 at 17:32













    0














    The problem was because the string was too long. Apparently the console in Eclipse has a character limit. Which is why i was seeing a blank value. This question here helped solve the issue:



    Character limit for System.out.println() in Java



    The solution is to:





    1. Go to Window > Preferences > Run/Debug > Console

    2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)







    share|improve this answer


























      0














      The problem was because the string was too long. Apparently the console in Eclipse has a character limit. Which is why i was seeing a blank value. This question here helped solve the issue:



      Character limit for System.out.println() in Java



      The solution is to:





      1. Go to Window > Preferences > Run/Debug > Console

      2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)







      share|improve this answer
























        0












        0








        0






        The problem was because the string was too long. Apparently the console in Eclipse has a character limit. Which is why i was seeing a blank value. This question here helped solve the issue:



        Character limit for System.out.println() in Java



        The solution is to:





        1. Go to Window > Preferences > Run/Debug > Console

        2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)







        share|improve this answer












        The problem was because the string was too long. Apparently the console in Eclipse has a character limit. Which is why i was seeing a blank value. This question here helped solve the issue:



        Character limit for System.out.println() in Java



        The solution is to:





        1. Go to Window > Preferences > Run/Debug > Console

        2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 17:54









        Jonathan Laliberte

        1,6042824




        1,6042824






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53241449%2fserver-cant-parse-something-in-ajax-post-parameter-what-is-causing-this%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







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings