Advertisement
mrnelgin

Untitled

Mar 4th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. I'm trying to get json from the NBA api site and it needs certain headers:
  2.  
  3.  
  4. wget -d -O - --header="Host: stats.nba.com" \
  5. --header="Connection: keep-alive" \
  6. --header="Accept: application/json, text/plain, */*" \
  7. --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' \
  8. --header="Origin: https://www.nba.com" \
  9. --header="Referer: https://www.nba.com/" \
  10. --header="Accept-Language: en-US,en;q=0.5" \
  11. --header="Sec-Fetch-Dest: empty" \
  12. --header="Sec-Fetch-Mode: cors" \
  13. --header="Sec-Fetch-Site: same-site" \
  14. --header="Sec-GPC: 1" \
  15. --header="Accept-Encoding: identity" \
  16. "https://stats.nba.com/stats/leaguestandingsv3?LeagueID=00&Season=2023-24&SeasonType=Regular+Season&SeasonYear="
  17.  
  18.  
  19. This works fine. sends me back some json.
  20.  
  21. Now if I try to do the same thing in JS
  22.  
  23.  
  24. 'use strict';
  25.  
  26. load('http.js');
  27. load('url.js');
  28.  
  29.  
  30. function getdata(endpoint,baseurl,headers) {
  31. var req = new HTTPRequest();
  32. req.AddExtraHeaders(headers);
  33. req.follow_redirects = 3;
  34. var contents = req.Get(endpoint+baseurl);
  35. writeln("Contents " + contents);
  36. }
  37.  
  38. var endpoint = 'https://stats.nba.com';
  39. var baseurl = '/stats/leaguestandingsv3?LeagueID=00&Season=2023-24&SeasonType=Regular+Season&SeasonYear=';
  40.  
  41. 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"};
  42.  
  43. getdata(endpoint,baseurl,headers);
  44.  
  45.  
  46. It's just hanging at the req.Get and eventually times out.
  47.  
  48.  
  49. writeln("Response Code: " + req.response_code);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement