我正在对此API发出Curl请求,但是无论我做什么都向我显示错误
MY API密钥= 34ca0e9b-ecdd-4736-a432-d87760ae0926
curl "https://www.lifeguard.insure/v1/quote" -H "Authorization: 34ca0e9b-ecdd-4736-a432-d87760ae0926" -X POST -H 'Content-Type: application/json' -d '{"category": "Auto","zipcode": "90293","age": 35, "gender": "Male", "key": "a2bf34ab-8509-4aa6-aa9e-13ae7917e1b8"}'
{“错误”:[“格式不正确的请求”]}
在文档中,它显示了这个https://www.lifeguard.insure/docs/#http-request
给出的代码是-
curl "https://www.lifeguard.insure/v1/quote" \
-H "Authorization: 34ca0e9b-ecdd-4736-a432-d87760ae0926" \
-X POST \
-H 'Content-Type: application/json' \
-d '{
"category": "Auto",
"zipcode": "90293",
"age": 35,
"gender": "Male",
"key": "a2bf34ab-8509-4aa6-aa9e-13ae7917e1b8"
}'
我的网站出了什么问题?还是API的问题?
答案 0 :(得分:0)
如果我对字符串使用双引号并转义包含的双引号(\"
),则请求有效:
curl "https://www.lifeguard.insure/v1/quote" -H "Authorization: 34ca0e9b-ecdd-4736-a432-d87760ae0926" -X POST -H "Content-Type: application/json" -d "{\"category\": \"Auto\",\"zipcode\": \"90293\",\"age\": 35, \"gender\": \"Male\", \"key\": \"a2bf34ab-8509-4aa6-aa9e-13ae7917e1b8\"}"
这似乎是Windows特有的问题,您不能在终端中使用单引号。该API文档可能会为Linux环境生成cURL代码。