![](/img/trans.png)
[英]Getting '400 Bad Request' when using multipart/form-data as Content-Type in XHR
[英]Multipart form data using XHR - Invalid Request
我正在使用FileUploader UI5 元素使用 XMLHttpRequest(POST 操作)上傳文件,下面是我的代碼片段 -
var input = document.querySelector('input[type="file"]');
var data = new FormData();
data.append("files", input.files[0]);
var xhr = new XMLHttpRequest();
xhr.open("POST","https://URL");
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader("apikey", "XXXXXXXXXXXXXXXXX");
xhr.setRequestHeader("accept", "application/json");
xhr.send(data);
但是在推送請求時,我遇到了異常。 不知道為什么我的后期操作會失敗,任何幫助將不勝感激。
錯誤描述 - 此服務至少需要 1 個文件。 請將您的文件放入 POST 請求的files
字段中”
這是請求標頭和有效負載的樣子 -
Request Header -
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
apikey:RGIukzqxB0GWhRaMMcCTmYGHnEWgk5qI
Connection:keep-alive
Content-Length:15
Content-Type:text/plain;charset=UTF-8
Host:sandbox.api.sap.com
Origin:https://webidetesting2532276-be010f3f7.dispatcher.us1.hana.ondemand.com
Referer:https://webidetesting2532276-be010f3f7.dispatcher.us1.hana.ondemand.com/extended_runnable_file.html?hc_orionpath=%2Fbe010f3f7%24S0015741697-OrionContent%2Fsap.ui.unified.sample.FileUploaderComplex&origional-url=index.html&sap-ui-appCacheBuster=&sap-ui-xx-componentPreload=off
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Request Payload -
[object Object]
您已經明確設置了 Content-Type 但它缺少 MIME 邊界參數。 完全省略標頭並允許 XHR 從 FromData 對象推斷 Content-Type。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.