0
我從nodejs文檔Link中提取了這段代碼,但是當我使用我的nodejs服務器運行時,它給了我這個錯誤。 有些堆棧溢出的人有同樣的錯誤,但我沒有找到解決方案。閱讀nodejs中的ECONNRESET錯誤
var postData = querystring.stringify({
'msg' : 'Hello World!'
});
var options = {
host: 'westus.api.cognitive.microsoft.com',
port: 443,
path: '/vision/v1.0/ocr?language=pt&detectOrientation=true',
method: 'POST',
headers: {'Ocp-Apim-Subscription-Key': 'API_KEY',
'Content-type': 'application/json'
}
};
var req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end',() => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});
// write data to request body
req.write(postData);
req.end();