Reputation:
Please click Server API Cors Error to see the issue i was facing yesterday, answered now.
The data that i am sending is/should be 'xlsx file' expected by server also
Now i am able to get Response headers as required but the Status now is Status Code:415 Unsupported Media Type from previous Status Code : 302 Authenticating. Also server should return an object but unluckily its returning 'Error: [object Object] undefined'
If any reference to the defined code is required, please refer the link above 'Server API Cors Error'
Below are the responses of the object to be returned in return of method POST, when it comes to Request Method - option, i am receiving proper status - 200 (ok)
Response- headers is below --
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:0
Date:Thu, 07 Sep 2017 09:59:22 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Requested header
Accept:application/json, text/plain
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
file-token : xxxxxxxxxxxxxxxxx
Connection:keep-alive
Content-Length:44
Content-Type:application/json
Host: xxxxxxxxxxxxxxx
Origin: http:xxxxxxxxxxxxxxxx
Referer: http:xxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent:Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
General Request
URL: http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Request Method:POST
Status Code:415 Unsupported Media Type
Remote Address: xxxxxxxxxxxxxxxxxxxxxxxxxx
Referrer Policy:no-referrer-when-downgrade
Upvotes: 1
Views: 10234
Reputation: 1129
I was receiving this error Status Code: 415 Unsupported Media Type, and I noticed in my server-side code it was expecting the parameters to come from the Body of the request so in PostMan I moved the parameters to the Body and it worked. Please check the example I created in the image below. Make sure you pass a JSON in the raw data tab and select the option "JSON (application/json)"
I hope it helps.
Upvotes: 0
Reputation:
The solution was ensuring that we define Accept also along with Content-type in headers. For example:
headers : { 'Content-type' : 'application/json', Accept : 'application/json'}
Upvotes: 1
Reputation: 5656
The problem is there are few CORS headers that you need to add:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
Access-Control-Allow-Headers: Content-Type
Your server is adding correctly the Access-Control-Allow-Origin header, but you need more. In the link that you have in the response of the previous post you referred, you have the cors specification for prefilight request, and it says that content-type it's not a normal header, when content-type is not application/x-www-form-urlencoded, multipart/form-data, or text/plain, the server must allow.
So to be ensure that you won't have more problems in this preflight request, you should add in the server side, the Access-Control-Allow-Headers and Access-Control-Allow-Methods headers.
Upvotes: 0