Add header options to downloadJSON

This commit is contained in:
pietervdvn 2021-08-22 15:53:25 +02:00
parent a2f3b967b7
commit 4bbcda1621

View file

@ -48,19 +48,22 @@ export default class ScriptUtils {
})
}
public static DownloadJSON(url): Promise<any> {
public static DownloadJSON(url, options?: {
headers: any
}): Promise<any> {
return new Promise((resolve, reject) => {
try {
const headers = options?.headers ?? {}
headers.accept = "application/json"
const urlObj = new URL(url)
https.get({
host: urlObj.host,
path: urlObj.pathname + urlObj.search,
port: urlObj.port,
headers: {
"accept": "application/json"
}
headers: headers
}, (res) => {
const parts: string[] = []
res.setEncoding('utf8');