我正在嘗試在Ruby中爲在此page中觸發的API請求創建一個rest-client請求。 (source)JavaScript的Blob rest-client API請求Blob
從頁面看JavaScript中,我注意到,有正在創建一個Javascript Blob和JSON的內容附加到,然後在多形式與下面的腳本提交 -
我試着用下面的代碼寶石,其餘的客戶端寶石仿效這一點 -
namespace :materialize do
task :connect => :environment do
base_uri = "https://imatsandbox.materialise.net/web-api/cartitems/register"
request = '{
"cartItems":[
{
"toolID":"d65e1eca-7adf-453d-a3bb-eb051fffb567",
"MyCartItemReference":"some reference",
"modelID":"62352bab-d490-410c-851d-bc62e056e82a",
"modelFileName":"",
"fileUnits":"mm",
"fileScaleFactor":"1",
"materialID":"035f4772-da8a-400b-8be4-2dd344b28ddb",
"finishID":"bba2bebb-8895-4049-aeb0-ab651cee2597",
"quantity":"1",
"xDimMm":"12",
"yDimMm":"159.94",
"zDimMm":"12",
"volumeCm3":"2.0",
"surfaceCm2":"100.0",
"iMatAPIPrice": "25.0",
"mySalesPrice": "26.0",
}
],
"currency":"EUR"
}'
File.open('request', 'wb') do |f|
f.write request
end
response = RestClient.post base_uri, {:data => request, headers: {:multipart => true, accept: :json}}
puts response.request
end
end
響應正文我總是 -
"{\"error\":{\"message\":\"Wrong request body. Check if all parameters set correctly\",\"code\":401},\"cartItems\":[]}"
我做錯了什麼?
也許如果我們看到你的服務器'log'是如何使這個'api'請求st我們可以弄清楚你在做什麼錯誤謝謝 –
當然,今天我會爲你解決這個問題。 –
這是我從你的源頁面得到的迴應https://imatsandbox.materialise.net/api/demo/cart-item-creation-api.html我得到了404。爲了幫助你,我需要看到這個迴應[! [https://i.stack.imgur.com/t4nOx.png]](https://i.stack.imgur.com/t4nOx.png) –