发送请求正文сURL

时间:2019-12-30 09:21:18

标签: json windows curl

我想传递请求正文,但对我来说不起作用,也许我写错了

class CarMotor():
def __init__(self):
    GPIO.setmode(GPIO.BCM)
    self.motor_lx = Motor(26, 21)
    self.motor_rx = Motor(16, 19)
    self.enable_lx = 13
    self.enable_rx = 20

    GPIO.setup(self.enable_lx, GPIO.OUT, initial=GPIO.HIGH)
    GPIO.setup(self.enable_rx, GPIO.OUT, initial=GPIO.HIGH)

3 个答案:

答案 0 :(得分:3)

您需要转义json正文或使用单引号将json包装起来

curl -X POST -H "Content-type: application/json" -d "{'time': '2019-12-27T09:50:02.000+0000', 'unread': 'true', 'message': 'hello','from':'Vadim'}"

或在Windows上

{{1}}

答案 1 :(得分:2)

您可以从邮递员那里获得crul命令 单击下拉菜单中的代码,获取cURL,该URL将提供可运行的cur命令

参考链接:https://learning.getpostman.com/docs/postman/sending-api-requests/generate-code-snippets/

如果您从中启用了Spring Boot APP,那么您也可以看到crul命令

答案 2 :(得分:0)

-X POST "{"time": "2019-12-27T09:50:02.000+0000", "unread:" "true", "message": "hello","from":"Vadim"}"

您的JSON无效。 {"unread:" "true"}应该是{"unread":"true"}

之后,您需要转义JSON的双引号:

-d "{\"time\":\"2019-12-27T09:50:02.000+0000\",\"unread\":\"true\",\"message\":\"hello\",\"from\":\"Vadim\"}"

很显然,我无法测试您的curl命令,但我认为这应该对您有用。