I have the following ajax request which works fine, but when i try the same through rest-client ruby gem i'm getting the following error
"{\"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: 'http://ift.tt/2u8jwRV'
data: data
cache: false
contentType: false
processData: false
beforeSend: (request) ->
request.setRequestHeader 'Accept', dataContentType
return
dataType: 'text'
success: (data, textStatus, jqXHR) ->
data variable contains this
{"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"}]}
I tried with the following using rest client
request = RestClient.post("http://ift.tt/2u8jwRV",{: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})
In coffee script it works fine, when i try in the rest client it throws mentioned error.
Aucun commentaire:
Enregistrer un commentaire