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