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) => { return new Promise((resolve, reject) => {
try { try {
const headers = options?.headers ?? {}
headers.accept = "application/json"
const urlObj = new URL(url) const urlObj = new URL(url)
https.get({ https.get({
host: urlObj.host, host: urlObj.host,
path: urlObj.pathname + urlObj.search, path: urlObj.pathname + urlObj.search,
port: urlObj.port, port: urlObj.port,
headers: { headers: headers
"accept": "application/json"
}
}, (res) => { }, (res) => {
const parts: string[] = [] const parts: string[] = []
res.setEncoding('utf8'); res.setEncoding('utf8');