arvindwill
arvindwill

Reputation: 1992

Content-type json returns http 404

In a 3rd party server when web application (serverside Struts 2) with EXt-JS 4 makes a ajax request with content-type: application/json; charset=utf-8 webserver returns page not found http 404/403 status code. But if we make the same request with plain text/html via browser url bar then response received. What will be the problem.

is there any way to simulate the request by sending in different content-type, i have tried below html form but it sends only Content-Type:application/x-www-form-urlencoded

<html>
<body>
<form action="http://abc.com/abc?" method="post" enctype="application/json; charset=utf-8">

<input type='submit'/>
</form>
</body>
</html>

Can a server or tomcat can restrict particular content-type alone?

<action name="abc" class="com.stutzen.rhs.abc.Abc" method="abc">
        <interceptor-ref name="json">
            <!--param name="contentType">application/json</param-->
        </interceptor-ref>
        <result type="json">
            <param name="excludeProperties">
                data,model
            </param>
        </result>
    </action>

Upvotes: 0

Views: 2819

Answers (1)

Alex Tokarev
Alex Tokarev

Reputation: 4861

You can set arbitrary headers on Ext side when making request with Ext.Ajax.request:

Ext.Ajax.request({
    url: '/foo',
    headers: {
        'Content-Type': 'text/html'
    }
});

However it looks more like a hack than true solution; you need to find out what server expects and proceed accordingly.

Upvotes: 1

Related Questions