如何使用CURL将获取请求发送到Web API?

时间:2020-09-29 07:23:36

标签: api curl postman webapi

我有一个Web API,当我使用Postman向它发送获取请求时,它可以正常工作。例如,API可以处理此请求:

http://localhost:5000/api/test/?id=23

当我尝试使用curl($ curl http://localhost:5000/api/test/?id=23)进行相同的操作时,出现此错误:

curl: (3) URL using bad/illegal format or missing URL

这是怎么了?

1 个答案:

答案 0 :(得分:0)

可能您的应用仅支持POST请求? curl http://localhost:5000/api/test/?id=23将发送GET请求。

尝试

curl -X POST http://localhost:5000/api/test/?id=23

如果这不起作用,则原因可能是请求标头,cookie或API中的(不太可能)用户代理处理。