[英]HTTP request not working on webpack-dev-server
我有這個簡單的 http 請求:
var http = require('http');
var data = JSON.stringify({
some: 'data'
});
var options = {
hostname: 'myhost.com',
port: 8080,
path: '/somePath',
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
var req = http.request(options, (response) => {
var buffer = '';
response.on('data', (chunk) => {buffer += chunk;});
response.on('end', () => {
console.log(buffer);
});
});
req.write(data);
req.end();
現在,當我使用 node 運行它時,這有效,但是當我捆綁它並在 webpack 服務器上運行它時,請求被發送但回調函數永遠不會被調用。 我知道這與異步請求有關。 任何想法為什么它不起作用?
我只是像普通人一樣使用 XMLHttpRequest ......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.