【问题标题】:PUT request using cURL and flask on windows在 Windows 上使用 cURL 和烧瓶 PUT 请求
【发布时间】:2015-07-24 13:30:30
【问题描述】:

这是我使用flask制作的rest web api中PUT方法的代码sn-p。

    @app.route('/lock-api/api/v1.0/items/<int:item_id>', methods=['PUT'])
    def update_item(item_id):
    item = [item for item in items if item['id'] == item_id]

    if len(item) == 0:
       abort(404)

    if not request.json:
       abort(400)

    if 'lock state' in request.json and type(request.json['lock state']) != unicode:
       abort(400)

    item[0]['lock state'] = request.json.get('item', item[0]['lock state'])
    return jsonify({'item': item[0]})    

PUT 请求的 curl 命令是

    curl -i -H "Content-Type: application/json" -X PUT -d "{"""lock state""":""""UNLOCKED"""}" http://localhost:5000/lock-api/api/v1.0/items/2

此命令应该更新同一文件中数组(项目)中条目的锁定状态,其中包含 2 个字段“id”和“锁定状态”,但没有这样做。谁能告诉我出了什么问题?我尝试添加一个追加,但它所做的只是在该数组中添加一个数组而不是更新它。 谢谢你

【问题讨论】:

    标签: python curl put


    【解决方案1】:

    在“UNLOCKED”之前,您的开放引号过多。

    但如果你使用单引号,你的命令会更简单:

    curl ... -d '{"lock state":"UNLOCKED"}' ...
    

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多