gpt4 book ai didi

javascript - Electron 响应并不总是返回 'end'

转载 作者:行者123 更新时间:2023-11-30 21:06:03 26 4
gpt4 key购买 nike

我正在编写读取 JSON 网络服务的小型 Electron 应用程序,我注意到有时“响应”对象不发送“结束”事件。知道我做错了什么吗?此外,我的 Web 服务在发送多部分分块数据时工作正常,我可以将其视为 console.log(BODY: ${chunk}) 的返回。

getDataBtn.addEventListener('click',function(event){
var autoryzator = document.getElementById('autoryzator').value;
var kwartal = document.getElementById('kwartal').value;
var rok = document.getElementById('rok').value;
console.log( `http://go/ankieta/default/purchase_order?approver=${autoryzator}&qtr=${kwartal}&year=${rok}`);
var request = net.request({
method: 'GET',
url: `http://go/ankieta/default/purchase_order?approver=${autoryzator}&qtr=${kwartal}&year=${rok}`,
port: 80
})
var authorize = document.getElementById('authorize');
var jsdata;
var data='';
console.log('connecting ...');
request.on('response', (response) => {
console.log(`STATUS: ${response.statusCode}`)
console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
response.on('data', (chunk) => {
console.log(`BODY: ${chunk}`)
var body = chunk.toString('utf8');
data=data+body
})
response.on('end', () => {
console.log('No more data in response.')
console.log(data)
jsdata=JSON.parse(data);
var data_ = jsdata['data'];

/// some app logic goes here
})
response.on('error', (error) => {
console.log(`ERROR: ${JSON.stringify(error)}`)
ret = JSON.stringify(error);
})
})
request.end();

})

最佳答案

你可以试试这个:

request.setHeader('Connection', 'keep-alive, close')
request.setHeader('Cache-Control', 'no-cache')
request.setHeader('Accept-Encoding', '*')

关于javascript - Electron 响应并不总是返回 'end',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46587659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com