I'm facing an issue with downloading a file from a specific URL when using a desktop browser, while it works perfectly on a mobile device (Chrome browser). I've thoroughly tested this in multiple desktop browsers and cleared the cache, but I'm still unable to figure out what's causing the problem.

When I click on the link in the desktop browser, I receive the following error message:

発行エラー: Failed to download file from the URL [https://example.com/7075626c6963/SmaPri/Label.spfmtz]. (The server committed a protocol violation. Section=ResponseHeader Detail='Content-Length' header value is invalid)

I've provided the JavaScript code responsible for this action below. The file is downloaded by calling the requestOutput() function. Here's the code:

function requestOutput() {
    var param1 = "__format_archive_url=" + encodeURIComponent('https://example.com/7075626c6963/SmaPri/Label.spfmtz');
    var param2 = "__format_id_number=2";
    var param3 = encodeURIComponent("Z.TanaBango") + "=" + encodeURIComponent("F1-1015") + "&" + encodeURIComponent("Barcode1") + "=" + encodeURIComponent("AXR12452") + "&" + encodeURIComponent("(Print quantity)") + "=" + encodeURIComponent(1);

    var url = "http://localhost:8080/Format/Print?" + param1 + "&" + param2 + "&" + param3;
    transaction(url, ResPrint); 
}

function ResPrint() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
            var xmlDoc = xmlhttp.responseXML;
            var result = xmlDoc.getElementsByTagName('result')[0].childNodes[0].nodeValue;
            var message = xmlDoc.getElementsByTagName('message')[0].childNodes[0].nodeValue;
            if (result == "OK") {
                // OK
            } else {
                // NG
            }
        } else {
            // Error
        }
    }
}

function transaction(url, method) {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = method;
    xmlhttp.open("GET", url, false);
    xmlhttp.send();
}

I've tested in multiple browser(windows, ubuntu18.04 LTS), clearing the cache not worked.

0

There are 0 best solutions below