0
我有一個input
標籤,type="file"
和一個使用Ajax將文件發送到Webapi端點的函數。
從html輸入發送文件到帶有Ajax的WebApi - 編碼問題
$('#myInput').change(function() {
if (this.files[0] === undefined) return;
sendToWebapi(this.files[0]);
this.value = null;
});
function sendToWebapi(file) {
const data = new FormData();
data.append('file', file);
$.ajax({
url: "myWebApiPath",
contentType: "text/csv",
processData: false,
method: "POST",
data: data
});
}
我的問題是,當發送到的WebAPI法國的字符不正確編碼。請參見下面的請求體的摘錄:
> ------WebKitFormBoundaryggBmtBMylhc9eoIE
Content-Disposition: form-data; name="file"; filename="myfile.csv"
Content-Type: application/vnd.ms-excel
Date;Pi�ce;Journal;Libell�;D�bit;Lettrage;Cr�dit;Solde
....
注意,同時增加字符集明確導致了我的請求主體被正確顯示,我的終點還是觀看字符串作爲前。 –
@François你的意思是「我的端點仍然像以前一樣查看字符串」? – Oscar
Myenpoint簽名是Task MyEndpointAsync([FromBody] List rows)。然後行中的每行都會看到像D bit這樣的東西。 –