Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I'm trying to get json from the NBA api site and it needs certain headers:
- wget -d -O - --header="Host: stats.nba.com" \
- --header="Connection: keep-alive" \
- --header="Accept: application/json, text/plain, */*" \
- --header='User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36' \
- --header="Origin: https://www.nba.com" \
- --header="Referer: https://www.nba.com/" \
- --header="Accept-Language: en-US,en;q=0.5" \
- --header="Sec-Fetch-Dest: empty" \
- --header="Sec-Fetch-Mode: cors" \
- --header="Sec-Fetch-Site: same-site" \
- --header="Sec-GPC: 1" \
- --header="Accept-Encoding: identity" \
- "https://stats.nba.com/stats/leaguestandingsv3?LeagueID=00&Season=2023-24&SeasonType=Regular+Season&SeasonYear="
- This works fine. sends me back some json.
- Now if I try to do the same thing in JS
- 'use strict';
- load('http.js');
- load('url.js');
- function getdata(endpoint,baseurl,headers) {
- var req = new HTTPRequest();
- req.AddExtraHeaders(headers);
- req.follow_redirects = 3;
- var contents = req.Get(endpoint+baseurl);
- writeln("Contents " + contents);
- }
- var endpoint = 'https://stats.nba.com';
- var baseurl = '/stats/leaguestandingsv3?LeagueID=00&Season=2023-24&SeasonType=Regular+Season&SeasonYear=';
- var headers = {"Host": "stats.nba.com", "Connection": "keep-alive", "Accept": "application/json, text/plain, */*", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", "Origin": "https://www.nba.com", "Referer": "https://www.nba.com/", "Accept-Language": "en-US,en;q=0.5", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-site", "Sec-GPC": 1, "Accept-Encoding": "identity"};
- getdata(endpoint,baseurl,headers);
- It's just hanging at the req.Get and eventually times out.
- writeln("Response Code: " + req.response_code);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement