因此,我拥有此方法,该方法应仅对活动端点进行调用并返回json字符串。我正在使用请求模块,但似乎无法解决此问题。
import request from 'request'
getCarbonId = (host: string): Promise<CarbonIdLookupResult> => {
return new Promise((resolve, reject) => {
const uri = 'http://' + host + '/remote-identify'
const formData = {}
const result = new CarbonIdLookupResult(host + '', '', -1, null)
request({ url: uri, form: formData, timeout: 10000 }, function onRet
error,
response,
body
) {
if (error) {
// tslint:disable-next-line:no-console
console.log('Error getting clid', error)
result.error = 'Error getting clid: ' + error
}
try {
const json = JSON.parse(body)
if (typeof json.carbonLitePlayerId !== 'undefined') {
result.clid = json.carbonLitePlayerId
} else {
result.error = json.error + ''
}
if (
typeof body !== 'undefined' ||
body!.indexOf('<!DOCTYPE html') > -1
) {
result.error = 'ERROR: Html message returned'
}
} catch (e) {
result.error = e.message
}
return resolve(result)
})
})
}
我收到此错误:
communicatorSync.ts:161 Uncaught (in promise) TypeError: request_1.default is not a function
at communicatorSync.ts:161
at new Promise (<anonymous>)
at CommunicatorSync.getCarbonId (communicatorSync.ts:156)
at communicatorSync.ts:103