最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Failed to execute 'setRequestHeader' on 'XMLHttpRequest' [...] is not a valid HTTP header

programmeradmin3浏览0评论

I am developing an application with AngularJS (client side) and Java (server side) using RESTful services (with Jersey).

In the client I have something like this

$http({
        url : "/Something/rest/...",
        method : "POST",
        headers : {
            ...
            'text' : text
        }
    });

on the server side my Java method header looks like this

 public JSONObject myMethod(@HeaderParam("text") String text [...]) throws JSONException

And I'm getting this error when trying to send a request

Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Some text here formatted with \n and \t' is not a valid HTTP header field value.

Is this because of the formatting? Is it because the text is quite long?

What should I change? Please guide me

I am developing an application with AngularJS (client side) and Java (server side) using RESTful services (with Jersey).

In the client I have something like this

$http({
        url : "/Something/rest/...",
        method : "POST",
        headers : {
            ...
            'text' : text
        }
    });

on the server side my Java method header looks like this

 public JSONObject myMethod(@HeaderParam("text") String text [...]) throws JSONException

And I'm getting this error when trying to send a request

Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Some text here formatted with \n and \t' is not a valid HTTP header field value.

Is this because of the formatting? Is it because the text is quite long?

What should I change? Please guide me

Share Improve this question edited Jun 20, 2014 at 12:30 Marius Manastireanu asked Jun 20, 2014 at 12:06 Marius ManastireanuMarius Manastireanu 2,5765 gold badges22 silver badges33 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

I had faced this problem. Please make sure that in your code header name doesn't contain space. i.e. 'designId ' is invalid, as it contain space at end

Are you sending your 'text' in headers on purpose? This is in general not a place for doing this. For sending content through POST(or GET) you should use 'data' field. So:

$http({
    url : "/Something/rest/...",
    method : "POST",
    data: {
        ...
        'text' : text
    }
});

,and on the server side similar change for getting your data from POST. You don't need and shouldn't mess with headers unless you know what you are doing.

I experience this a few days back. I simply clear my cookies and other site data and it was able to resolve the issue.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论