0
我需要將json文件傳遞給API,但它看起來像我需要在JSON文件發送到API之前做一些事情。錯誤是「無法解碼JSON數據」。何處添加內容類型 - 應用程序/ JSON格式爲html?錯誤 - 無法解碼JSON數據
<form name="myform" enctype="multipart/form-data" action="https://api-106.dxi.eu/ecnow.php" method="POST" enctype='application/json'>
<input type="hidden" name="method" value="ecnow_records">
<input type="hidden" name="token" value="xxxxxxxxxxxxxxxxxxxxx">
<input type="hidden" name="action" value="create">
<input type="hidden" name="format" value="json">
<input type="hidden" name="raw" value="1">
Send this file: <input name="easycall" type="file">
<input type="submit" value="Send json File">
</form>
它工作正常,當我嘗試郵遞員並將JSON粘貼到Body-> Raw中。我不確定Body-> Raw在HTML表單中的確切位置?
請指教。
在此先感謝
您在窗體中使用了'enctype =「multipart/form-data」'。順便說一句,你不能在這裏使用原始的JSON體,因爲你有輸入字段文件。 – Suresh
謝謝。那麼我可以使用什麼樣的enctype。 –
截至目前,瀏覽器將不支持'enctype ='application/json''。默認值將是URL表單編碼。對於ref,https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype。請使用ajax請求發送json作爲原始有效載荷。 – Suresh