Why do I get “Error parsing HTTP request header” when POSTing a JSON string?

前端 未结 6 1056
我寻月下人不归
我寻月下人不归 2021-02-09 13:29

I am trying to send a POST request from browser to my server(local host). My request URL is :

 http://localhost:8080/myPath/myServlet?requestData={          


        
相关标签:
6条回答
  • 2021-02-09 13:31

    I fixed this by passing an additional header

    connection: close, along with the request.

    Could you please try and let me know if this works for you.

    0 讨论(0)
  • 2021-02-09 13:37

    In my case problem was caused by security issues, i used csfr for authentication, and all my post forms should have input with _csrf

    <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
    
    0 讨论(0)
  • 2021-02-09 13:37

    IMHO the problem of parsing the headers can be caused by numerous reasons.

    In my case it was due to the fact that the following XML was passed:

    <soapenv:Header/>
    

    The empty header element was generated by SoapUI. After the removal of the <soapenv:Header/> from the XML of the WS then everything was fine.

    0 讨论(0)
  • 2021-02-09 13:49

    It seems that you are using POST incorrectly. Although you are using POST you are sending JSON as a request parameter that is the GET style. When using POST you should send content as a request body. In this case no reasonable size limitation exist.

    0 讨论(0)
  • 2021-02-09 13:51

    I had a similar issue, I was sending a POST request (using RESTClient plugin for Firefox) with data in the request body and was receiving the same message.

    In my case this happened because I was trying to use HTTPS protocol in a local tomcat instance where HTTPS was not configured.

    0 讨论(0)
  • 2021-02-09 13:51

    I apologize for not answering questions seriously before.

    1.Maybe it caused by special characters.You can get details from this url。https://bz.apache.org/bugzilla/show_bug.cgi?id=60594

    solve it by:

    encodeURIComponent(JSON.stringify(data))
    

    or change your tomcat version to 7.0.67 or lower. According to developers's opinion, tomcat developers in the following versions set the option to allow |,{,}. Get detail http://tomcat.apache.org/tomcat-8.0-doc/config/systemprops.html#Other

    The new environment variable will be included in: - trunk for 9.0.0.M18 onwards

    • 8.5.x for 8.5.12 onwards

    • 8.0.x for 8.0.42 onwards

    • 7.0.x for 7.0.76 onwards2.

    Another reason maybe that Request header is too large.You can solve this by modifying the server.xml.

    <Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" 
        minSpareThreads="25" maxSpareThreads="75" enableLookups="false"
        redirectPort="8443" acceptCount="100" connectionTimeout="20000" 
        disableUploadTimeout="true" />
    

    Hope it works for you!

    0 讨论(0)
提交回复
热议问题