1

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.

webstackdev
  • 850
  • 15
  • 23
  • I noticed a question by [someone getting 406 errors](https://stackoverflow.com/questions/67394866/api-gives-406-code-with-accept-application-json-request-bluehost) with requests to Bluehost and they confirmed it was because Bluehost was actively blocking `Accept: application/json` headers. I'm not sure how to test if `json.schemastore.org` is doing the same though. – webstackdev Sep 30 '21 at 02:38

1 Answers1

2

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
David Hempy
  • 5,373
  • 2
  • 40
  • 68