Curl 卷曲图

Curl 卷曲图,curl,graphql,Curl,Graphql,我试图在CMD中卷曲我的GraphQL查询,这是我在下面使用的格式。问题是它抛出了一个错误{“errors”:[{“message”:“POST body发送了无效的JSON.}]}*,有时会将主机api.spacex.land的连接#0保持完整。我的查询格式与下面给出的完全相同。问题是什么 { users { id } } 当我使用您的命令时: curl -v -d '{"query": "{users {id}}"}' -H &qu

我试图在CMD中卷曲我的GraphQL查询,这是我在下面使用的格式。问题是它抛出了一个错误{“errors”:[{“message”:“POST body发送了无效的JSON.}]}*,有时会将主机api.spacex.land的连接#0保持完整。我的查询格式与下面给出的完全相同。问题是什么

{
  users {
    id
  }
}


当我使用您的命令时:

curl -v -d '{"query": "{users {id}}"}' -H "Content-Type: application/json" https://api.spacex.land/graphql/
我得到以下错误:

/
curl: (3) nested brace in URL position 8:
{users {id}}}'
       ^
这可能与您的服务器消息“PostBody发送了无效的JSON”相同,对吗


现在,当您通过在外部使用双引号并转义内部双引号来修复json数据时,它应该可以工作:

curl -v -d "{\"query\": \"{users {id}}\"}" -H "Content-Type: application/json" https://api.spacex.land/graphql/
答复内容:

*   Trying 54.227.160.247:443...
* Connected to api.spacex.land (54.227.160.247) port 443 (#0)
* Intentionally shortened, because lots of handshaking... 
*  SSL certificate verify ok.
> POST /graphql/ HTTP/1.1
> Host: api.spacex.land
> User-Agent: curl/7.72.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 25
>
* upload completely sent off: 25 out of 25 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Cowboy
< Connection: keep-alive
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Content-Length: 619
< Etag: W/"26b-G4MLTIIWM/zsAMBAAg0mhhU/k0o"
< Date: Wed, 07 Oct 2020 11:43:08 GMT
< Via: 1.1 vegur
<
{"data":{"users":[{"id":"455d8432-c423-46e1-9124-5b5f111bd799"},{"id":"643ea1ec-ae3e-4cfa-9b2d-5a9b62fd9b7f"},{"id":"974d8432-c423-46e1-9124-5b5f111bd799"},{"id":"981d8432-c423-46e1-9124-5b5f111bd749"},{"id":"11cd2db5-3e6e-4363-b8e5-afd2a67a5333"},{"id":"8da63d00-b5f1-4260-92a3-4c98c329f60a"},{"id":"11cd2db5-3e6e-4363-b8e5-afd2a67a5332"},{"id":"c7fdb3f3-5af8-45e7-aa9c-6259d0a636ef"},{"id":"ca73c5b8-10f6-4586-abf9-0407726ed5c4"},{"id":"1c70a7b7-ac51-4fdc-b9ef-f21b65918611"},{"id":"643ea1ec-ae3e-4cfa-9b2d-5a9b62fd9b8f"},{"id":"781d8432-c423-46e1-9124-5b5f111bd799"},{"id":"310d8432-c423-46e1-9124-5b5f111bd799"}]}}
* Connection #0 to host api.spacex.land left intact
*   Trying 54.227.160.247:443...
* Connected to api.spacex.land (54.227.160.247) port 443 (#0)
* Intentionally shortened, because lots of handshaking... 
*  SSL certificate verify ok.
> POST /graphql/ HTTP/1.1
> Host: api.spacex.land
> User-Agent: curl/7.72.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 25
>
* upload completely sent off: 25 out of 25 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Cowboy
< Connection: keep-alive
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Content-Length: 619
< Etag: W/"26b-G4MLTIIWM/zsAMBAAg0mhhU/k0o"
< Date: Wed, 07 Oct 2020 11:43:08 GMT
< Via: 1.1 vegur
<
{"data":{"users":[{"id":"455d8432-c423-46e1-9124-5b5f111bd799"},{"id":"643ea1ec-ae3e-4cfa-9b2d-5a9b62fd9b7f"},{"id":"974d8432-c423-46e1-9124-5b5f111bd799"},{"id":"981d8432-c423-46e1-9124-5b5f111bd749"},{"id":"11cd2db5-3e6e-4363-b8e5-afd2a67a5333"},{"id":"8da63d00-b5f1-4260-92a3-4c98c329f60a"},{"id":"11cd2db5-3e6e-4363-b8e5-afd2a67a5332"},{"id":"c7fdb3f3-5af8-45e7-aa9c-6259d0a636ef"},{"id":"ca73c5b8-10f6-4586-abf9-0407726ed5c4"},{"id":"1c70a7b7-ac51-4fdc-b9ef-f21b65918611"},{"id":"643ea1ec-ae3e-4cfa-9b2d-5a9b62fd9b8f"},{"id":"781d8432-c423-46e1-9124-5b5f111bd799"},{"id":"310d8432-c423-46e1-9124-5b5f111bd799"}]}}
* Connection #0 to host api.spacex.land left intact
curl -H "Content-Type: application/json" --data @your-json-file.json http://localhost:port/api-end-point