0

When i am trying to pass large string i.e., converted the file in to binary and passing to webapi as string , if the file size is above 45, the below error is coming

XMLHttpRequest cannot load http://localhost/api/Order/UploadFile. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost is therefore not allowed access. The response had HTTP status code 404.

how can i rectify this...please help me..

chaitanya k
  • 199
  • 1
  • 3
  • 14
  • http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource check this – Rajath M S Apr 21 '17 at 04:55
  • This question has already asked many times in StackOverflow, please check the other related questions first. – Rajath M S Apr 21 '17 at 05:00

1 Answers1

0

AS @Rajath mentioned this question is already answered in many SO questions:

Solution in brief: This is a CORS issue:

I can think of a couple of solutions:

a. Add following to the response header or tomcat config:

 Access-Control-Allow-Origin: http://siteA.com
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: Content-Type 

b. Put this to the tomcat conf/web.xml or your server side application's web.xml:

  <filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, POST, HEAD, PUT, DELETE</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>Content-Type, Last-Modified</param-value>
        </init-param>
        <init-param>
            <param-name>cors.exposedHeaders</param-name>
            <param-value>Set-Cookie</param-value>
        </init-param>
        <init-param>
            <param-name>cors.supportsCredentials</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>CORS</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Also see: HTTP access control (CORS) Hope this helps.

OutOfMind
  • 874
  • 16
  • 32