An error occurred when the proxy server built by node requested static resources.

in the interface returned to me by the background, there is an absolute path to the image. For example, the background ip is 11.11.1, and the image path is / res/default.jpg. I enter 11.11.1/res/default.jpg in the URL to see the picture, but it doesn"t show
I sent the request through the client, wrote the agent with node, got the response, got the image path information and gave it to the src attribute of the img tag.

this is my node agent code

else if (pathname == "/res/default.jpg") {
        (function() { 
            var options = {
                host: "11.11.1", 
                path: pathname, 
                method: "get" 
            };
            console.log(pathname);
            let req = http.request(options, function(req) { 
                req.on("data", function(chunk) {
                    sendmsg += chunk; 
                });
                req.on("end", function(d) { 
                    var list = JSON.stringify(sendmsg); 
                    response.writeHead(200);
                    response.end(sendmsg);
                });
            });
            req.end(); 
        })()
    }      

then the js sends the request code

        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
                    var text = JSON.parse(xhr.responseText);
                    var imgsrc= text["data"]["list"][0]["picture"];
                    document.getElementsByTagName("img")[0].setAttribute("src", imgsrc);
                } else {
                    alert("error: " + xhr.status);
                }
            }
        }
        var url = "/Blog/listAll/1"
        xhr.open("get", url, true);
        xhr.send(null);

the URL of the picture in the browser is http://127.0.0.1:8080/res/default.jpg. But I found that its type is octet-stream,. I don"t know if it will be the problem here

Mar.19,2021

Yes, this is the default value, which means unknown file.

< H2 > add < / H2 >

Web

the browser determines that the format is only based on MIME . If you return Content-Type from a css file as image/jpeg , he will actually regard the file as an image, even if you are a .css suffix.

attachment

the browser determines that the format is parsed only based on the file suffix and the specific format of the file (for example, .jpg changed to .txt ).

back to the question, application/octet-stream represents an unknown file, indicating some kind of binary stream data, and the browser's behavior is to download. Opening through the address bar means downloading the cost attachment and then opening it through the browser.

Menu