jsoncurlcontent-typehttp-accept-language

Requesting JSON file with `Accept: application/json` giving `resource cannot be displayed` error


I'm trying to fetch a JSON file from a well-known endpoint (json.schemastore.org) using @actions/http-client. I'm getting an error with that client, and the same error trying the request with cURL:

$ curl --header "Accept: application/json" https://json.schemastore.org/eslintrc.json
The resource cannot be displayed because the file extension is not being accepted by your browser.

Adding a Content-Type header to the request causes it to succeed and return the JSON file, but only if it precedes the Accept header in the list passed to cURL (Accept: application/json;Content-Type: application/json causes the same error mentioned above):

curl --header "Content-Type: application/json;Accept: application/json" https://json.schemastore.org/eslintrc.json

The request also succeeds if I omit the --header param to cURL:

curl https://json.schemastore.org/eslintrc.json

With the above (no header parameter), cURL is sending this request:

GET /eslintrc.json HTTP/1.1
Host: json.schemastore.org
User-Agent: curl/7.71.1
Accept: */*

The response headers received from json.schemastore.org using the above cURL command (no header parameter) are:

HTTP/1.1 200 OK
Cache-Control: public,max-age=31536000
Content-Length: 47049
Content-Type: application/json; charset=utf-8
Last-Modified: Fri, 10 Sep 2021 17:59:28 GMT
Accept-Ranges: bytes
ETag: "1abc4d996da6d71:0"
Vary: Accept-Encoding, If-Modified-Since
Server: Microsoft-IIS/10.0
Content-Security-Policy: object-src 'none';
Arr-Disable-Session-Affinity: True
Access-Control-Allow-Origin: *
Date: Thu, 30 Sep 2021 02:06:18 GMT

The body of the response is the JSON document.

Can anyone help me understand why just using an Accept: application/json header on the request doesn't work? There's no body in the request, so it doesn't seem like the Content-Type header should be having any effect? And why would the order of the Content-Type and Accept header, passed as arguments to cURL, make any difference? I'm thinking maybe it's some behavior of IIS that I don't understand.


Solution

  • I don't think you can specify multiple headers in one argument. Try adding separate --header arguments:

    curl \
      --header "Content-Type: application/json" \
      --header "Accept: application/json" \
      https://json.schemastore.org/eslintrc.json