簡體   English   中英

IE11:在IE11中Content-Type = false無效

[英]IE11 : Content-Type = false in IE11 it doesn't work

比我嘗試使用方法beginQuoteFileUnquoteUpload1更好的第一個解決方案是它為我創建了一個很好的邊界和一個良好的Content-Type,但是當我收到文件時。 該文件已損壞:(

 var formData = new FormData(); formData.append('file', document.getElementById('file').files[0], document.getElementById('file').files[0].name); function beginQuoteFileUnquoteUpload1(data) { // Define a boundary, I stole this from IE but you can use any string AFAIK var boundary = "---------------------------7da24f2e50046"; var xhr = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } }else{ xhr = new XMLHttpRequest(); } }else{ alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest..."); return; } var body = '--' + boundary + '\\r\\n' + 'Content-Disposition: form-data; name="file";' + 'filename="'+document.getElementById('file').files[0].name+'"\\r\\n' + 'Content-type: application/pdf\\r\\n\\r\\n' + data + '\\r\\n' + '--'boundary + '--'; var url ="https://gedcreditor.mycloud.by/Myproject/ws/rest/sendemail/"; url+=document.getElementById('file').files[0].name; url+="/a/a/a"; xhr.open("POST", url, true); xhr.setRequestHeader( "Content-type", "multipart/form-data; boundary="+boundary); xhr.setRequestHeader('Authorization','Bearer ' + JWTtoken);//Our test server does not accept JWt, once we use AXA server, we will test the JWT xhr.setRequestHeader('ApiKey','lRABmnmS_H1Ej9yaowxqwEsuBbkxkgrzx-C1Jji_HfnJyKywR8NeuSkIJbhutfNg'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) alert("File uploaded!"); } xhr.send(body); } beginQuoteFileUnquoteUpload1(formData); 

******************************結果******************* ***************

----------------------------- 7da24f2e50046 ----->好的內容處置:form-data; name =“ file”; filename =“ servlet.pdf”內容類型:application / pdf

--------------------------- 7da24f2e50046-- Content-Type multipart / form-data; boundary = --------------------------- 7da24f2e50046 ---->確定

================================================== ================================================== =============================================

第二種解決方案確實起作用,因為防火牆阻止了我,因為我在方法和結果下沒有相同的界限。

 var formData = new FormData(); formData.append('file', document.getElementById('file').files[0], document.getElementById('file').files[0].name); function beginQuoteFileUnquoteUpload(data) { // Define a boundary, I stole this from IE but you can use any string AFAIK var boundary = "---------------------------7da24f2e50046"; var xhr = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } }else{ xhr = new XMLHttpRequest(); } }else{ alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest..."); return; } var url ="https://gedcreditor.mycloud.by/GEDCREDITOR_01_06/ws/rest/sendemail/"; url+=document.getElementById('file').files[0].name; url+="/a/a/a"; xhr.open("POST", url, true); xhr.setRequestHeader( "Content-type", "multipart/form-data; boundary="+boundary); //xhr.setRequestHeader('Authorization','Bearer ' + JWTtoken);//Our test server does not accept JWt, once we use AXA server, we will test the JWT // xhr.setRequestHeader('ApiKey','lRABmnmS_H1Ej9yaowxqwEsuBbkxkgrzx-C1Jji_HfnJyKywR8NeuSkIJbhutfNg'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) alert("File uploaded!"); } xhr.send(data); } beginQuoteFileUnquoteUpload(formData); 

******************************結果******************* ***************

CléValeur Content-Type多部分/表單數據; boundary = --------------------------- 7da24f2e50046 ------>確定

----------------------------- 7e018a1b2079a ------> Ko Content-Disposition:表單數據; name =“文件”; filename =“ servlet.pdf”內容類型:application / pdf

Ç¥¾}«?s

第二種方法是正確的方法,除了沒有設置內容類型標頭。 使用FormData對象發出請求時,將自動正確地設置它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM