休息客户端发布请求,多部分错误

时间:2017-07-12 10:50:18

标签: ruby-on-rails ruby rest ruby-on-rails-3 coffeescript

我有以下ajax请求,工作正常,但当我通过rest-client ruby​​ gem尝试相同时,我收到以下错误

"{\"error\":{\"message\":\"Wrong request body. Check if all parameters set correctly\",\"code\":401},\"cartItems\":[]}"

JS:

    dataContentType = 'application/json'
    data = new FormData
    if dataContentType == 'text/xml'
      data.append 'data', new Blob([ $('#requestXml').val() ], type: 'text/xml')
    else
      data.append 'data', new Blob([ $('#requestJson').val() ], type: 'application/json')
      console.log('requestJson', $('#requestJson').val())
    fileIdx = 0
    $('input[type=file]').each (i, value) ->
      `var i`
      i = 0
      while i < value.files.length
        data.append 'file[' + fileIdx + ']', new Blob([ value.files[i] ], type: 'application/octet-stream'), value.files[i].name
        fileIdx++
        i++
      return
    $.ajax
      type: 'POST'
      url: 'https://imatsandbox.materialise.net/web-api/cartitems/register'
      data: data
      cache: false
      contentType: false
      processData: false
      beforeSend: (request) ->
        request.setRequestHeader 'Accept', dataContentType
        return
      dataType: 'text'
      success: (data, textStatus, jqXHR) ->

数据变量包含此

{"currency":"USD","cartItems":[{"toolID":"toolID","MyCartItemReference":"some reference","modelID":"modelID","modelFileName":"","fileUnits":"mm","fileScaleFactor":"1","materialID":"00e005a8-b29b-4196-ba4e-57ac1c4ce60c","finishID":"bba2bebb-8895-4049-aeb0-ab651cee2597","quantity":"1","xDimMm":81.266,"yDimMm":159.935,"zDimMm":10.096,"volumeCm3":15.5864,"surfaceCm2":260.288,"iMatAPIPrice":"25.0","mySalesPrice":"26.0"}]}

我尝试了以下使用rest client

request = RestClient.post("https://imatsandbox.materialise.net/web-api/cartitems/register",{:currency => "USD",:cartItems => [{:toolID => "toolID",:MyCartItemReference => "some reference",:modelID => "modelID",:modelFileName => "",:fileUnits => "mm",:fileScaleFactor => "1",:materialID => "00e005a8-b29b-4196-ba4e-57ac1c4ce60c",:finishID => "bba2bebb-8895-4049-aeb0-ab651cee2597",:quantity => "1",:xDimMm => "81.266",:yDimMm => "159.935",:zDimMm => "10.096",:volumeCm3 => "15.5864",:surfaceCm2 => "260.288",:iMatAPIPrice => "25.0",:mySalesPrice => "26.0"}], :multipart => true})

在咖啡脚本中,它工作正常,当我在其余客户端尝试时,它会抛出提到的错误。

编辑: enter image description here

0 个答案:

没有答案