【问题标题】:CURL script errorsCURL 脚本错误
【发布时间】:2018-08-29 18:26:43
【问题描述】:

我正在尝试在我的 curl 脚本中测试 create 方法,但是当我在终端中运行命令时出现错误:

"{"error":{"message":"无法将 undefined 或 null 转换为 object","error":{}}}scripts/jobs/create.sh: 第 15 行: --data: command 没找到”

这是我的工作架构中的内容:

'use strict'

const mongoose = require('mongoose')

const jobSchema = new mongoose.Schema({
    url: {
    type: String,
    required: true
  }
})
const Job = mongoose.model('Job', jobSchema)

module.exports = Job 

我的工作管理员:

'use strict'

const controller = require('lib/wiring/controller')
const models = require('app/models')
const Job = models.jobs

const create = (req, res, next) => {
  const job = Object.assign(req.body.job, {})
  Job.create(job)
    .then(job =>
      res.status(201)
        .json({
          job: job.toJSON()
          // ({ virtuals: true, user: req.user })
        }))
    .catch(next)
}

module.exports = controller({
  create
})

我的create CURL 脚本:

API="http://localhost:4741"
URL_PATH="/jobs"

curl "${API}${URL_PATH}" \
  --include \
  --request POST \
  --header "Content-Type: application/json" \
  # --header "Authorization: Token token=${TOKEN}" \
   --data '{
    "job": {
      "url": "'"${URL}"'"
    }
  }'

echo

【问题讨论】:

    标签: javascript node.js curl mongoose


    【解决方案1】:

    CURL 脚本不允许在多行标志之间使用 cmets。

    删除# --header "Authorization: Token token=${TOKEN}" \

    如果需要,也可以取消注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 2020-04-08
      • 2020-01-26
      • 2019-07-06
      • 2012-03-06
      • 2019-02-08
      相关资源
      最近更新 更多