forked from MapComplete/MapComplete
Add header options to downloadJSON
This commit is contained in:
parent
a2f3b967b7
commit
4bbcda1621
1 changed files with 7 additions and 4 deletions
|
@ -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');
|
||||||
|
|
Loading…
Add table
Reference in a new issue