SHARE
TWEET

Untitled

a guest Jan 21st, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   static get(path: string, options: RequestOptions = { query: {}, proxy: null }): Promise<string> {
  2.     const endpoint = url.parse(path);
  3.     if (!/https?:/.test(endpoint.protocol)) {
  4.       return Promise.reject(new Error(`Unsupported protocol: "${endpoint.protocol}"`));
  5.     }
  6.     let queryString = qs.stringify(options.query);
  7.     if (queryString) {
  8.       queryString = `?${queryString}`;
  9.     }
  10.     if (options.proxy) {
  11.       return this.getWithProxy(endpoint, options.proxy, queryString);
  12.     } else {
  13.       if (endpoint.protocol === 'http:') {
  14.         return Http.get(endpoint.hostname, endpoint.path + queryString);
  15.       } else {
  16.         return Https.get(endpoint.hostname, endpoint.path + queryString);
  17.       }
  18.     }
  19.   }
  20.  
  21.   static post(path: string, params?: { [id: string]: any }): Promise<string> {
  22.     const endpoint = url.parse(path);
  23.     if (!/https?:/.test(endpoint.protocol)) {
  24.       return Promise.reject(new Error(`Unsupported protocol: "${endpoint.protocol}"`));
  25.     }
  26.     if (endpoint.protocol === 'http:') {
  27.       return Http.post(endpoint, params);
  28.     } else {
  29.       return Https.post(endpoint, params);
  30.     }
  31.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top