我有一个
input
type="file"
以及一个使用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
....